1.Find the error(s) and show how to correct it(them) in each of the following.a.Filepets.datthat stores its id, name, age and ownerof the pet is referred to by ofstream objectpetfile.petfile>>pet_id>>pet_name>>pet_age>>pet_owner;b.The following statement should create an ifstream objectsalesfilethat refers to the fileweeklysales.datthat contains data about the id thesalesperson, total sales generated, and theweek number, read the data from the file and display it on the console output.ifstream salesfile(“weeklysales.dat”);int id,wk;float sales;salesfile>>id>>wk>>sales;while (!salesfile.eof()){cout<<id<<”\t”<<sales<<”\t”<<wk<<”\n”;salesfile<<id<<wk<<sales;}c.The salaries.dat should be updated to include the salary details of new employees. An ofstreamobject is created to refer to the file so new data can be added at the end of the file.ofstream salfile;salfile.open(“salaries.dat”,ios::out);
Comments
Leave a comment