Exemplo n.º 1
0
int main ( int argc, char *argv[] )
{
	//Sales_data total;
	Sales_data total = Sales_data();
	Sales_data out = Sales_data("outnum", 8, 8.5);
	print(cout, out) << endl;;
	
	if(read(cin,total))
	{
		Sales_data trans = Sales_data("");
		while (read(cin,trans))
		{
			if (total.isbn() == trans.isbn())
				total.combine(trans);
			else {
				print(cout, total) << endl;
				total = trans;
			}
		}
		print(cout, total) << endl;
	}
	else
	{
		cerr << "No data?!" << endl;
	}
	return 0;
}				/* ----------  end of function main  ---------- */
Exemplo n.º 2
0
void func(string infileName, string outfielName)
{
	ifstream infile(infileName);
	ofstream outfile(outfielName, ostream::app);

	if (!infile.is_open())
	{
		cerr << "error in open file: " << infileName;
		exit(1);
	}

	Sales_data total;
	if (read(infile, total))
	{
		Sales_data trans;
		while (read(infile, trans))
		{
			if (total.isbn() == trans.isbn())
			{
				total.combine(trans);
			}
			else
			{
				print(outfile, total) << endl;
				total = trans;
			}
		}
		print(outfile, total) << endl;
	}
	else
	{
		cerr << "no data?" << endl;
	}
}
Exemplo n.º 3
0
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
	Sales_data sum = lhs;
	sum.combine(rhs);

	return sum;
}
Exemplo n.º 4
0
int main(int argc, char const *argv[])
{
    Sales_data total;
    std::ifstream in(argv[1]);
    if (read(in, total))
    {
        Sales_data trans;
        while (read(in, trans))
        {
            if (total.isbn() == trans.isbn())
            {
                total.combine(trans);
            }
            else
            {
                print(cout, total) << endl;
                total = trans;
            }
        }
        print(cout, total) << endl;
    }
    else
    {
        cerr << "No data" << endl;
    }
    return 0;
}
Exemplo n.º 5
0
// The transaction-processing program
// Mostly copied from 7.3.cpp with some modifications
int main() {
  // variable to hold data for the next transaction
  Sales_data total;
  // read the first transaction and ensure that there are
  // data to process
  if (read(cin, total)) {
    // variable to hold the running sum
    Sales_data trans;
    while (read(cin, trans)) {
      // if we're still processing the same book
      if (total.isbn() == trans.isbn()) {
	// update the running total
	total.combine(trans);
      }
      else {
	// print results for the previous book
        print(cout, total) << endl;
	// Total now refers to the next book
	total = trans;
      }
    }
    // print the last transaction
    print(cout, total) << endl;
  }
  else {
    // no input! warn the user
    cerr << "No data?!" << endl;
    return -1; // indicate failure
  }
  return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    if(argc != 3)
    {
        cerr << "Wrong input!" << endl;
        return -1;
    }
    ifstream input(argv[1]); // open the file of sales transactions
    ofstream output(argv[2]); // open the output file
    Sales_data total; // variable to hold the running sum
    if (read(input, total)) // read the first transaction
    {
        Sales_data trans; // variable to hold data for the next transaction
        while(read(input, trans)) // read the remaining transactions
        {
            if(total.isbn() == trans.isbn()) // check isbns
                total.combine(trans); // update the running total
            else
            {
                print(output, total) << endl; // print the results
                total = trans; // process the next book
            }
        }
        print(output, total) << endl; // print the last transaction
    }
    else
    {
        cerr << "No data?!" << endl; // no input
    }
    return 0;
}
Exemplo n.º 7
0
int main(int argc, char* argv[]){
    if( argc < 2){
        cerr << "arguments are not enough" << endl;
        exit(1);
    }
    string fileName = argv[1];
    ifstream input(fileName);
    if(input){
        Sales_data total;
        if(read(input, total)){
            Sales_data trans;
            while(read(input, trans)){
                if(total.isbn() == trans.isbn())
                    total.combine(trans);
                else{
                    print(cout, total) << endl;
                    total = trans;
                }
            }
            print(cout, total) << endl;
        }else{
            cerr << "No data?!" << endl;
        }
    }
}
Exemplo n.º 8
0
int main() {
  Sales_data total;
  if (read(std::cin, total)) {
  //double price;
  //if (std::cin >> total.bookNo >> total.units_sold >> price) {
  //  total.revenue = total.units_sold * price;
    Sales_data trans;
    while (read(std::cin, trans)) {
    //while (std::cin >> trans.bookNo >> trans.units_sold >> price) {
    //  trans.revenue = trans.units_sold * price;
      if (total.isbn() == trans.isbn()) {
        total.combine(trans);
      } else {
        print(std::cout, total) << std::endl;
        //std::cout << total.bookNo << " "
        //          << total.units_sold << " "
        //          << total.revenue << std::endl;
        total = trans;  // Use default copy constructor
      }
    }
    print(std::cout, total) << std::endl;
    //std::cout << total.bookNo << " "
    //          << total.units_sold << " "
    //          << total.revenue << std::endl;
  } else {
    std::cerr << "No data!" << std::endl;
    return -1;
  }

  return 0;
}
Exemplo n.º 9
0
Sales_data 
add(const Sales_data &lhs, const Sales_data &rhs)
{
	Sales_data sum = lhs;  // copy data members from lhs into sum
	sum.combine(rhs);      // add data members from rhs into sum
	return sum;
}
Exemplo n.º 10
0
int main(){

  Sales_data total;
  
  if(read(cin,total)){
	  
	  Sales_data trans;
	  while(read(cin,trans)){
		  
		  if(total.isbn() == trans.isbn()){
			  total.combine(trans);
			  
		  }else{
			  
			  print(cout,total) << endl;
			  total = trans;
		  }
	  }
	  
	  print(cout,total) << endl;
	  
  }else{
	  
	  cerr << "No data ?! " << endl;
  }  

}
Exemplo n.º 11
0
int main()
{
    Sales_data total;           // variable to hold the running sum
    if (read(cin, total))
    {                           // read the first transaction
        Sales_data trans;       // variable to hold data for the next transaction
        while(read(cin, trans)) // read the remaining transactions
        {
            if (total.isbn() == trans.isbn()) // check the isbns
            {
                total.combine(trans);         // update the running total
            }
            else
            {
                print(cout, total) << endl;   // print the results
                total = trans;                // process the next book
            }
        }
        print(cout, total) << endl;           // print the last transaction
    }
    else
    {                                         // there was no input
        cerr << "No data?!" << endl;          // notify the user
    }
    return 0;
}
Exemplo n.º 12
0
int main(int argc, char const *argv[])
{
	Sales_data total;
	if(read(std::cin, total))
	{
		Sales_data trans;
		while(read(std::cin, trans))
		{
			if(total.bookNo == trans.bookNo)
			{
				total.combine(trans);
			}
			else
			{
				print(std::cout, total) << std::endl;
				total = trans;
			}
		}
	    print(std::cout, total) << std::endl;
	}
	else
	{
		std::cerr << "No data" << std::endl;
	}
	return 0;
}
Exemplo n.º 13
0
int main(int argc, char **argv)
{
    ifstream input(argv[1]);
    ofstream output(argv[2], ofstream::app);
    
    Sales_data total;
    if (read(input, total))
    {
        Sales_data trans;
        while (read(input, trans))
        {
            if (total.isbn() == trans.isbn())
                total.combine(trans);
            else
            {
                print(output, total) << endl;
                total = trans;
            }
        }
        print(output, total) << endl;
    }
    else
    {
        cerr << "No data?!" << endl;
    }
    
    return 0;
}
int main(int argc, char * argv[]) 
{
    Sales_data just_isbn_book("123456789-D");               //test usage of partial constructor.OK it compiles
    print(cout , just_isbn_book) ; cout << endl;
    Sales_data full_book("123456789-F", 3, 38.8, "Effective C++"); //test usage of full constructor.OK it compiles 
    print(cout , full_book) ; cout << endl;
    cout << "\tAfter testing the 2 constructors, we read form the file supplied in the command line " << endl;
    if(argc == 1) //input file name passed with redirection < filename
    {
    	 Sales_data total(cin);  //using the constructor for initialization: reading input e.g. from a file, or from console
    	 if( !total.isbn().empty() ) 
    	 { 
           Sales_data trans;           // variable to hold data for the next transaction
           while( read(cin, trans) ) 
           {
              if ( total.isbn() == trans.isbn() ) total.combine(trans);  
              else 
              {                                  
                print(cout , total ) ; cout<<endl; 
                total = trans ;                
              }
           }
           print( cout, total ) ; cout<<endl;     
         } 
         else std::cerr << "No data?!" << endl;   
     }
     else if (argc == 2) // input file passed as command line arg
     {
     	ifstream input_file(argv[1]);
     	Sales_data total;
     	if (read(input_file, total)) 
     	{ // read the first transaction
		Sales_data trans;		// variable to hold data for the next transaction
		while(read(input_file, trans)) 
		{							// read the remaining transactions
		        if (total.isbn() == trans.isbn()) // check isbn s
			    total.combine(trans); // update the running total
			else 
			{
				print(cout, total) << endl; // print the results
				total = trans;					// process the next book
			}
		}
		print(cout, total) << endl; // print the last transaction
	} else									// there was no input
	    cerr << "No data?!" << endl;
     }
     return 0;
}
Exemplo n.º 15
0
int main(){
    Sales_data total;
    if(cin >> total.bookNo >> total.units_sold >> total.revenue){
        Sales_data trans;
        while(cin >> trans.bookNo >> trans.units_sold >> trans.revenue){
            if(trans.isbn() == total.isbn()){
                total.combine(trans);
            }else{
                cout << total.bookNo << " " << total.units_sold
                    << " " << total.revenue << endl;
                total = trans;
            }
        }
        cout << total.bookNo << " " << total.units_sold << " " << total.revenue << endl;
    }else{
Exemplo n.º 16
0
int main()
{
    Sales_data total;
    if(read(cin, total)){
        Sales_data trans;
        while(read(cin, trans)){
            if(total.isbn()== trans.isbn())
                total.combine(trans);
            else{
                print(cout, total)<<endl;
                total= trans;
            }
        }
        print(cout, total)<<endl;
    }
    else{
        std::cerr<<"No data!" <<endl;
        return -1;
    }
    return 0;
}
Exemplo n.º 17
0
void ReportForSalesData8_08(const std::string& filein, const std::string& fileout)
{
	std::ifstream ifs(filein);
	if (!ifs)
	{
		std::cerr << "open file \"" << filein << "\" error." << std::endl;
	}

	std::ofstream ofs(fileout, std::ofstream::app);
	if (!ofs)
	{
		std::cerr << "open file \"" << fileout << "\" error." << std::endl;
	}

	Sales_data total;
	if (read(ifs, total)) //输入为文件流ifs
	{
		Sales_data trans;
		while (read(ifs, trans))
		{
			if (total.isbn() == trans.isbn())
			{
				total.combine(trans);
			}
			else
			{
				print(ofs, total) << std::endl; //输出到一个文件ofs流
				total = trans;
			}
		}

		print(ofs, total) << std::endl;
	}
	else
	{
		std::cerr << "No data." << std::endl;
	}

	ifs.close();
}
Exemplo n.º 18
0
int main(int argc, char *argv[]) {
        ifstream ifst(argv[1]);
	ofstream ofst(argv[2], ofstream::app);
        Sales_data total;
        if (read(ifst, total)) {
                Sales_data trans;
                while (read(ifst, trans)) {
                        if (total.isbn() == trans.isbn()) {
                                total.combine(trans);
                        }
                        else {
                                print(ofst, total) << endl;
                                total = trans;
                        }
                }
                print(ofst, total) << endl;
        }
        else {
                std::cerr << "No Data?!" << endl;
        }
        return 0;
}
Exemplo n.º 19
0
int main()
{
	Sales_data total;
	if (read(cin, total)) {
		Sales_data trans;
		while (read(cin, trans)) {
			if (total.isbn() == trans.isbn())
				total.combine(trans);
			else {
				print(cout, total) << endl;
				total.bookNo = trans.bookNo;
				total.units_sold = trans.units_sold;
				total.revenue = trans.revenue;
			}
		}
		print(cout, total) << endl;
	} else {
		cerr << "No data?!" << endl;
		return -1;
	}
	return 0;
}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
    if (argc != 2) {
        cerr << "Usage: \"Exercise 8.6\" filename" << endl;
        return 0;
    }
    ofstream output(argv[1], ofstream::app);    
    Sales_data total;           
    if (read(cin, total)) {
        Sales_data trans;
        while (read(cin, trans)) {
            if (total.isbn() == trans.isbn())
                total.combine(trans);
            else {
                print(output, total) << endl;
                total = trans;
            }
        }
        print(output, total) << endl;   // print the last transaction
    } else
        cerr << "No data?!" << endl;    
    return 0;
}
Exemplo n.º 21
0
Sales_data add(const Sales_data &book1, const Sales_data &book2)
{
	Sales_data temp = book1;
	temp.combine(book2);
	return temp;
}
Exemplo n.º 22
0
Sales_data add(const Sales_data &lhs, const Sales_data &rhs) {
  Sales_data sum = lhs;  // Use default copy constructor
  sum.combine(rhs);
  return sum;
}
Exemplo n.º 23
0
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
	Sales_data total = lhs;
	total.combine(rhs);
	return total;
}