刚学C++,有些不会...

来源:百度知道 编辑:UC知道 时间:2024/05/26 04:23:04
Write a program that reads data from the keyboard and creates a text
file called "used.car". Prompt the user to enter manufacturer, model,year, miles and cost of each car. After creating the file, close it,and then reopen it for reading. Read components from the file and display records that satisfy the following conditions: miles<50000 and cost<9000.

写一个程序,要求从键盘输入相关数据,并且创建成文本文件,叫做“used。car”
提示用户输入:(汽车的)生产厂家,型号,年份,里程数,年耗费。
创建文件后,关闭它,然后再次打开用于读取。
从文件中读取并且显示满足下列条件的记录:里程数<50000,年耗费<9000.

#include<iostream>
#include<fstream>
using namespace std;
class Car
{
public:

char name[20]; //生产厂家
int size; //型号
int year; //年份
long length; //里程数
int money; //年耗费
void Input();
void Output();
};
void Car::Input()
{
cout<<"请输入厂家:";cin>>name;
cout<<"\n请输入型号:";cin>>size;
cout<<"\n请输入年份:";cin>>year;
cout<<"\n请输入里程:";cin>>length;
cout<<"\n请输入年耗:";cin>>money;
}
void Car::Output()
{
cout<<name<<endl;
cout<<size<<endl;
cout<<year<<endl;
cout<<length<<endl;
cout<<money<<endl;
}
int main()
{
int i=1,j=0;
Car A,B;
ofstream outfile("usecar.txt",ios::out);
while(i!=0)