this is one example can you try to troubleshoot it... thanks Code: #include<iostream> #include<fstream> #include<iomanip> #include<string> #include<cstdlib> using namespace std; void outputline(int, const string, const string,int, int); void showRecords(); void inputRecords(); int main(){ int c; start: cout<<"Press:" <<"\n[1] Show Records" <<"\n[2] Input Records"<<endl; cin>>c; switch(c){ case 1: showRecords(); cout<<endl; goto start; break; case 2: inputRecords(); system("cls"); goto start; break; default: goto exit; } exit: cin.ignore(); cin.get(); } void showRecords(){ ifstream inClientFile("Student.txt", ios::in); //open file for output int studentid,units,tuition; string name, course; //print header cout<<left<<setw(15)<<"Student ID"<<setw(17)<<"Student Name"<<setw(10)<<"Prog Code"<<setw(10)<<"Units"<<setw(10)<<"Tuition"<<endl; //output the content of the file by calling the function while(inClientFile>>studentid>>name>>course>>units>>tuition) outputline(studentid, name, course,units,tuition); } void inputRecords(){ //open the file for input ofstream outClientFile("Student.txt", ios::app); //check if the file exists if (!outClientFile) { cerr<< "File could not be opened."; exit (1); } //prompt the user to enter data cout<<"Enter the 10-digit student number, name, program code,no. of units"<<endl; cout<<"Enter end of file to end input."<<endl<<"?"; int studentid,units,tuition; string name, course; //user will enter data tuition=units*250; while(cin>>studentid>>name>>course>>units>>tuition) {outClientFile << studentid <<" "<< name <<" "<< course<<" "<<units<<" "<<tuition<<endl;break;} } //this will iterate until there's data to read void outputline(int studentid, const string name, const string course, int units, int tuition) { cout<<left<<setw(15)<<studentid<<left<<setw(17)<<name<<left<<setw(10)<<course<<setw(10)<<units<<setw(10)<<tuition<<endl; }
Inheritance is sub class of main class and mostly it defines by class in common program. Your example is true but you can use class because it is easy to write and also understand. As example we define “class A†then enter “public:†into it, Now can define “class B : public Aâ€. This is called inheritance.