#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include"Student.cpp"


void main()
{
    clrscr();
    int choice;
    student s;
    cout<<"MCA EXAM MANAGEMENT SYSTEM"<<endl<<endl
    <<"1. Login"<<endl
    <<"2. Register"<<endl;

    cin>>choice;

    switch(choice)
    {

        case 1 :        clrscr();
                        cout<<"1. Student Login"<<endl
                        <<"2. Teacher Login"<<endl;

                        cin>>choice;


                        if(choice==1)
                        {
                                s.studentLogin();
                                cout<<endl<<"back to main";

                        }

                        else if(choice==2)
                        {

                            //Call to login function of teacher class

                        }


                        else
                        cout<<"Invalid choice"<<endl;

                        break;


        case 2:     clrscr();
                    cout<<"1. Student Register"<<endl
                    <<"2. Teacher Register"<<endl;

                    cin>>choice;

                    if (choice==1)
                    {
                        //Call to register function of student class
                    }

                    else if(choice==2)
                    {
                         //Call to register function of teacher class
                    }

                    else
                    cout<<"Invalid choice"<<endl;

                    break;

                    default: cout<<"Invalid choice"<<endl;
                    break;

    }


        getch();

}

I'm creating an object s of the class "student" which is imported in the file "Main.cpp". Here's what goes wrong with the code

  1. Login
  2. Register

enter 1

  1. Student Login
  2. Teacher Login

enter 1 (This invokes the studentLogin() method of the class student using "s" object)

The method executes successfully and then returns to the switch case.

Now "back to main" is printed.

After this, on pressing any key, the compiler hangs and I have to force quit.

I tried to find out the problem and it seems to the "s.studentLogin()" method call. When I comment that statement, the code doesn't break. Why is this happening?

What compiler are you using? All of you includes are depreciated. It is <iostream> not <iostream.h>. Also you are inlcuding a cpp file. You never want to do that. Your student class should be defined in two files. xxxx.h and xxxx.cpp. The .h file is what you should be including in any .cpp file that needs students. the .cpp file should then be added to the project that you are using it in. void main is not standard, main only returns an int.

I'm using Turbo C++. And it says "Unable to open "iostream" when I remove the ".h" extension. And including the cpp file seems to work fine though. And are the two different .h and .cpp files supposed to be in the same directory. If yes, what's the use of the .cpp file if I'm only going to include the .h one?

void main is not standard, main only returns an int.

I don't follow.

All of you includes are depreciated.

Deprecated, not depreciated. Also, since <iostream.h> and <conio.h> were never standard in the first place, they cannot be deprecated. They're just non-standard.

The .h file will hold the definition of you class. The .cpp file holds the declaration of your class. According to the standard the function main has two valid signatures. int main() and int main(int argc, char * argv[])

I'm using Turbo C++.

Turbo C++ doesn't support standard C++. You'd be wise to upgrade to a compiler that isn't over 20 years old. But if you continue to use Turbo C++, take note that you're stuck with pre-standard C++ and all of the limitations that come with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.