0

I am doing this code for my university project, I tried it with getter functions but it was not running either and it is not assigning values to the class member and not displaying the values back and Neither search modify functions are working it seems they are not able to access the class members, I am working on it for more than hours and know I cannot get any idea why is it not working, Can anybody help?

#include<iostream>
#include<string>
using namespace std;
void intro();
void entry_menu();
void getdata();
void display();
void search();
void Modify();
int count;
class student {
public:
    string name[50];
    string fname[50];
    string regNo[50];
    int rollNo[50];
    void getdata();
    void showdata();
    void search();
    int numberstudents;
};
class course {
public:
    string courseId;
    string courseName;
    void getdata();
    void showdata();
    void availableCourse();
};
class transcript {
public:
    int currentSemester;
    int previousSemester;
    void getdata();
    void showdata();
};
class fee {

};
student s;
int main() {
    char choice=0;
    intro();
    do
    {
        system("cls");
        cout<<"\n\n\n\tMAIN MENU";
        cout<<"\n\n\t01. ENTRY/EDIT MENU";
        cout<<"\n\n\t02. FEE";
        cout<<"\n\n\t03. TRANSCRIPT";
        cout<<"\n\n\t04. EXIT";
        cout<<"\n\n\tPlease Select Your Option (1-4) ";
        cin>>choice;
        switch (choice)
        {
        case '1': entry_menu();
            break;
        case '2': 
            break;
        case '3':
            break;
        default:cout << "\a";
        }
    } while (choice!= '4');
    return 0;

}
void intro()
{
    cout<<"\n\n\n\t\t  =============================================================================";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";  
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                  STUDENT                                  ||";
    cout<<"\n\n\t\t  ||                                 MANAGEMENT                                ||";
    cout<<"\n\n\t\t  ||                                   SYSTEM                                  ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||                                                                           ||";
    cout<<"\n\n\t\t  ||===========================================================================||";
    cout<<endl<<"                                               *****Press Enter*****                      "<<endl;
    cin.get();
}
void entry_menu()
{   
    char ch;
    int num;
    system("cls");
    cout << "\n\n\n\tENTRY MENU";
    cout << "\n\n\t1.CREATE STUDENT RECORD";
    cout << "\n\n\t2.DISPLAY ALL STUDENTS RECORDS";
    cout << "\n\n\t3.SEARCH STUDENT RECORD ";
    cout << "\n\n\t4.MODIFY STUDENT RECORD";
    cout << "\n\n\t5.DELETE STUDENT RECORD";
    cout << "\n\n\t6.BACK TO MAIN MENU";
    cout << "\n\n\tPlease Enter Your Choice (1-6) ";
    cin >> ch;
    system("cls");
    switch (ch)
    {
    case '1':      
    getdata(); 
    break;
    case '2':     
    display(); 
    break;
    case '3':
    search();
    break;
    case '4':
    Modify();
    break;
    }

}
void getdata(){
    cout<<"Enter The Number of students who's data you want to enter:  ";cin>>s.numberstudents;
    cout<<"***********************Enter The Data of the Students****************************"<<endl;
    for(int i=0;i<=s.numberstudents-1;i++){
    cout<<"\n\nEnter The Name of the Student ";
    cin.ignore();
    getline(cin,s.name[i]);
    cout<<"\n\nEnter The Father Name of the Student ";
    cin.ignore();
    getline(cin,s.fname[i]);
    cout<<endl;
    cout<<"Enter Registration Number: ";
    cin.ignore();
    getline(cin,s.regNo[i]);
    cout<<endl;
    cout<<"Enter Roll Number: ";
    cin>>s.rollNo[i];
    system("cls");
}
    cout<<"You have successfully saved "<<s.numberstudents<<" records\n";
}
void display(){
   for(int j=0; j<=s.numberstudents-1; j++)
   {
    cout<<"\n\nThe Name of the Student ";
    cout<<s.name[j];cout<<endl;
    cout<<"\n\nThe Father Name of the Student ";
    cout<<s.fname[j];cout<<endl;
    cout<<"Registration Number: ";
    cout<<s.regNo[j];cout<<endl;
    cout<<"Roll Number: ";
    cout<<s.rollNo[j];cout<<endl;
    }
}
void search(){
    int srchCat,srchID,flag;
    string srchNam;         //These will ask what the user wants to search
            cout<<"What do you wish to search?"<<endl;
            cout<<"1 for Roll No"<<endl;
            cout<<"2 for Name"<<endl<<endl;
            cin>>srchCat;
            cout<<endl;

            if (srchCat==1){
                cout<<"Enter Roll No: ";
                cin>>srchID;
                for (count=0; count<10; count++){
                    if (srchID==s.rollNo[count]){
                    flag=1;
                    break;
                    }
                }
                if (flag==1)
                cout<<"This ID belongs to "<<s.name[count]<<endl;
                else
                cout<<"Not Found"<<endl;
            }

            if (srchCat==2){
                cout<<"Enter Name: ";
                cin.ignore();
                getline(cin,srchNam);
                for (count=0; count<10; count++){
                    if (srchNam==s.name[count]){
                    flag=1;
                    break;
                    }
                }
                if (flag==1)
                cout<<"This student has ID "<<s.rollNo[count]<<endl;
                else
                cout<<"Not Found"<<endl;
            }
        }
void Modify(){
    bool found;
    string edit;
    cout<<"please enter name or father name of student for search to add his record\n";
    cin.ignore();
    getline(cin,edit);
    for(int j=0; j<=count;j++)
    {
    if(edit==s.name[j] || edit==s.fname[j])
    {
    cout<<"Old record \n"<<"student name : "<<s.fname[j]<<endl<<"Father name : "<<s.name[j]<<endl<<"Student roll no : "
    <<s.rollNo<<endl;
    cout<<"please enter new record\n";
    getline(cin,s.name[j]);
    cout<<"please enter new student father name\n";
    getline(cin,s.fname[j]);
    cout<<"please enter new roll no\n";
    cin>>s.rollNo[j];
    system("cls");
    cout<<"you have successfuly re-edit the date\n";
    found=1;
 }
} 
    if(found==0)
    {
    cout<<"Not found\n";
   }
 }
cosmoonot
  • 2,161
  • 3
  • 32
  • 38
  • 1
    We'll we've covered what it's *not* doing. How about what it *is* doing, along what you're expectations are, and the difference between those. And fyi, your `using namespace std;` proliferation causes build failure on my rig due to ambiguous reference to `count`. (1) Terrible idea to make that a global, and (b) [bad idea to slurp the entire `std` namespace unnecessarily into global](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). Just saying. – WhozCraig Dec 17 '19 at 17:30
  • Please specify what "not working" means. What errors did you get? What input did You give the program? What output did You get? What did You expect will happen? – Robert Andrzejuk Dec 17 '19 at 17:30
  • And have you tried printing `s.numberstudents` anywhere? – Gem Taylor Dec 17 '19 at 17:32
  • I cannot compile your code . Complaining about count variable not present. Did you even successfully compile this code ? – user3389943 Dec 17 '19 at 17:38
  • ***I cannot get any idea why is it not working*** Anytime you find yourself in this position you should use your debugger to step through your code 1 line at a time and look at the variables after each step. If this is Visual Studio learn what the F9, F10 and F11 keys do. Those are the most important keys in debugging when using Visual Studio (any version). The following link gives you some links on how to use a debugger in many different IDEs: [http://idownvotedbecau.se/nodebugging/](http://idownvotedbecau.se/nodebugging/) – drescherjm Dec 17 '19 at 18:14
  • I was able to compile this with gcc after removing the `system("CLS");` calls. It seemed to work fine minus the `cin.ignore()` chopping off characters. I would imagine that would hamper your search functionality... – Jason Dec 17 '19 at 19:39

1 Answers1

0

display() function actually works. you dont see it because system("cls") removes it from the screen immidiately after it is printed. Here are a few recommendations:

add cin.get() to all switch cases to wait for user input (enter key) in int main()function

switch (choice)
{
 case '1':
  entry_menu();
  cin.get();

in void entry_menu() function

switch (ch)
{
 case '1':
  getdata();
  cin.get();
  break;
 case '2':
  display(); 
  cin.get();
  break;
 case '3':
  search();
  cin.get();
  break;
 case '4':
  Modify();
  cin.get();
  break;

getdata() and display() function can look like this

void getdata(){
  cout<<"Enter The Number of students who's data you want to enter:  ";
  cin>>s.numberstudents;
  cout<<"***********************Enter The Data of the Students****************************"<<endl;
  for(int i=0; (i <= (s.numberstudents - 1)); i++){
  cin.ignore();
  cout<<"\nEnter The Name of the Student: ";
  getline(cin, s.name[i]);
  cout<<"Enter The Father Name of the Student: ";
  getline(cin, s.fname[i]);
  cout<<"Enter Registration Number: ";
  getline(cin, s.regNo[i]);
  cout<<"Enter Roll Number: ";
  cin>>s.rollNo[i];
  cout<<"\n................................\n";
  }
  cout<<"You have successfully saved "<<s.numberstudents<<" records\n";
}

void display(){
 cout << "................................\n";
 for(int j=0; (j <= (s.numberstudents - 1)); j++)
 {
  cout<<"\nThe Name of the Student ";
  cout<< s.name[j] <<endl;
  cout<< "The Father Name of the Student ";
  cout<< s.fname[j] << endl;
  cout<< "Registration Number: ";
  cout<< s.regNo[j] << endl;
  cout<< "Roll Number: ";
  cout<< s.rollNo[j] <<endl;
  cout<<"\n................................";
  }
}