actually i have a lot of problems with code down. i actually i made this code to let create a file for several student, i tried by my name but unfortunately i got alot of errors i don't know how can i debug them. if anyone of you know how to complete the program by making the user to enter so many student and their marks and let the user to make some modification or edit his or her names, i want at least 100 student to enter their names, ids,marks, and display the name, the id,the avarage marks for each student in files,this is the code,
i wish i can get a complete program. please help me and thank you, it is really important, i am really thankful for all of you,have a great time guys
i wish i can get a complete program. please help me and thank you, it is really important, i am really thankful for all of you,have a great time guys
Code:
#include<iostream> #include<fstream> using namespace std; const int SIZE=100; class Info{ private: string id; double mark; public: Info(); void display(); void getData(); void setMark(double); // change the value. double getMark(); // assest the value string getName(); }; Info:: Info(){ id=" "; mark=0; } void Info:: getData(){ cout<<" please enter the student id:"<<endl; getline(cin,id); cout<<" please enter the student mark:"<<endl; cin>> mark; std:: cin.ignore(); } void Info:: display(){ cout<<id<< "\t"<< mark << endl; } void Info::setMark(double m){ mark=m; } double Info::getMark(){ return mark; } void save(Info s[], int SIZE){ ofstream myfile; myfile.open("mark.sami"); for( int i=0; i<SIZE; i++) myfile<< s[i].getName <<"\t"<<s[i].mark<<endl<<endl;; myfile.close(); } void load(){ string line; ifstream myfile("mark.sami"); if(myfile.is_open()) { while(! myfile.eof()) { getline(myfile,line); cout<<line<< endl; } myfile.close(); } else cout<< " Unable to open file"<<endl; } int main() { Info std[SIZE]; for(int i=0; i<SIZE; i++) std[i].getData(); cout<<" \nName\tmark"<<endl; cout<<"=========================="<<endl; // load(); for(int i=0; i<SIZE; i++) std[i].display(); save(std,SIZE); return 0; }
Comment