我真的需要你帮助我的C ++作业,这是我应该做的:
1:用户可以创建txtfile然后输入
2:如果用户搜索该特定txtfile,程序应该显示txtfile的内容
3:用户应该能够在运行程序时编辑txtfile的内容
如果之前已经回答过但我找不到答案,我很抱歉。请保持代码尽可能简单,因为我还不熟悉编程。我真的需要你的帮助。非常感谢你。
BTW,我使用Turbo C ++作为编译器
这是我的代码:
#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
#include<conio.h>
int main()
{
clrscr();
char name[20], course[20], age[2], num[15], address[30];
char gender[1], bday[15], fn[30], focc[20], mn[30], mocc[20];
char ans, file[30];
int x;
do{
ofstream myfile;
cout<<"File Name: ";
cin>>file;
myfile.open(file,ios_base::out);
cout<<"Student Information \n\n";
cout<<"Name: ";
myfile<<"Name: "<<gets(name);
cout<<"Gender: ";
myfile<<"\nGender: "<<gets(gender);
cout<<"Age: ";
myfile<<"\nAge: "<<gets(age);
cout<<"Address: ";
myfile<<"\nAddress: "<<gets(address);
cout<<"Birthday: ";
myfile<<"\nBirthday: "<<gets(bday);
cout<<"Course: ";
myfile<<"\nCourse: "<<gets(course);
cout<<"Father's name: ";
myfile<<"\nFather's Name: "<<gets(fn);
cout<<"Occupation: ";
myfile<<"\nOccupation: "<<gets(focc);
cout<<"Mother's Name: ";
myfile<<"\nMother's Name: "<<gets(mn);
cout<<"Occupation: ";
myfile<<"\nOccupation: "<<gets(mocc);
myfile.close();
cout<<"\n\nDo you want to edit? [y/n]";
ans = getche();
//ansy
if(ans=='y')
{
clrscr();
x=1;
}
else if (ans=='n')
{
x=0;
}
else
{
cout<<" Invalid choice";
x=0;
}
}while(x!=0);
getch();
return 0;
}