Answer to Question #268213 in C++ for Gopi

Question #268213

write a program to store the data of mobile shop in a file with appropriate data members and member functions. use read and writes method to perform the file operations. read only the price and model value of mobile from file.

1
Expert's answer
2021-11-18T06:55:52-0500


#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>




using namespace std;








int main()  {
	string fileName="mobiles.txt";
	ifstream mobilesFstream(fileName);
	if(!mobilesFstream){
		cout << "The file '"<<fileName<<"' does not exist.\n";
	}else{
		string model;
		float price;
		while(!mobilesFstream.eof()){
			mobilesFstream>>price;
			getline(mobilesFstream,model);
			cout<<"Model: "<<model;
			cout<<", price: "<<price<<"\n";
		}
		
	}
	mobilesFstream.close();
	cin>>fileName;
	return 0;  
}


The filename "mobiles.txt"


45.99 Samsung Galaxy F62

15.99 Nokia X4

20.99 Nokia H5


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS