السلام عليكم ....
عندي سؤال في ال c++
برنامج class بسيط يقرأ ويعطي درجات 10 طلاب
كيف ممكن أخلي يقرأ ويكتب في تكست فايل (fstream)
أنا عملتو يكتب في فايل بس بدي لما أشغل البرنامج مره ثانية أخلي يقرأ من نفس الفايل
الرجاء نسخ الكود ولصقه في تكست فايل والمحاذاه الى اليسار لقرائته صحيحا
كود البرنامج :
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
class exam
{
private:
float score [10];
int i;
public:
void intialize(void)
{
for(i=0;i<10;i++)
{
score=-1;
}
}
void enter_score (void)
{
cout<<"Enter Student Number"<<endl;
cin>>i;
cout<<"Enter Student Score"<<endl;
cin>>score;
ofstream outfile("fdata.txt");
for(i=0;i<10;i++)
outfile<<"the score of student "<< i <<" is "<<score<<endl;
}
void get_score (void)
{
cout<<"Enter Student Number"<<endl;
cin>>i;
if(score==-1)
cout<<"no score for this student"<<endl;
else
cout<<"the score of student "<< i <<" is " <<score<<endl;
}
};
int main()
{
exam exam1;
int i;
exam1.intialize();
do
{
cout<<"1)Enter Score"<<endl;
cout<<"2)Get Score"<<endl;
cout<<"3)Exit"<<endl;
cin>>i;
if(i==1)
exam1.enter_score();
if(i==2)
exam1.get_score();
}
while(i!=3);
return 0;
}