how to create a file named "Mobiledata.txt"containing information of 20 mobiles ,includes brand,model,price,color and usage time ?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Mobile
{
private:
string brand;
string model;
int price;
public:
mobile()
mobile(brand,model,color,...)
int getprice()
};
int main ()
{
public:
string brand,model,color;
int price,years
int i;
mobile arr[20];
ifstream in;
in.open("mobiledata.txt");
for (i=0;i<20;20;i++)
}
Creating the file is not that difficult, figuring out where to place the file so the program can find it can be hard.
First think about what type of data you will be storing, i.e., ints, doubles, strings or something else. The order can make reading the file very easy or very hard. Sometimes it is easier to put a string at the end of a line of input data. Then you might have to consider if your data can be separated with a space or would a coma work better.
In this case I might consider everything as a string with each field separated by comas and use the string function "stod" to convert "price" to a double. Just a thought for now until I have more to work with like an actual sample of your input file and what code you have started with.
Are you trying to create a program that lets you input these values and then places the information into a file? For example creating a class called mobilePhone and then using all the variables above into this class. Then you would need 20 instances of that class each with its own data. Is this what you want to do?