I need help with this code

Constructer is abnormally called again n again.... add these file 2 a project n run ...i've given given constant messages in da code to explain the problem!

Hit (1) two tyms i.e GetInput function in da menu.... u'll get 2 knw wat da problem is...

i've created an array of objects ....n when i jump 2 da next index da values of old index's r chenged to da default values ( da values assinged in constructer)!!!!

i've attached the files of prject...!

Attachments
#include"AR.h"

#include<iostream>
using namespace std;
#include<conio.h>
#include<stdio.h>
AR::AR(
	  
	   
	   ){}
int AR::stdcount;

void AR::getInput(){
system("cls");
			
					cout<<"Enter Roll NO:"<<endl;
				 cin>>arr[stdcount].rollNo; 

				 
				 cout<< "The current index is holding the same value of roll no i.e arr["<<stdcount<<"].rollno is: "<<arr[stdcount].rollNo<<endl;
				 			
				 cout<<endl<<endl<<"But abnormally when this function is called again for the next index,the old value of arr[0].rollno (the previous index) is changed to the constructer value!!! constructer is bieng called abnormally. "<<endl<<endl;
				 
                 stdcount==1? cout<<"Now the roll no of 0th index is:"<<arr[0].rollNo<<",Which is the default value in costructer. It should be called only once when the instance was created! "<<endl : cout<<"Go for option(1)i.e GetInput once again in the menu "<<endl<<endl;	
				 
				 system("pause");
				 /*
				 cout<<endl<<"Enter Name:"<<endl;
				 cin>>arr[stdcount].name;

                 cout<<"Enter Quiz # 1 Marks "<< endl;
                 cin>>arr[stdcount].q1marks;
                 
                 cout<<"Enter Quiz # 2 Marks: "<< endl;
                 cin>>arr[stdcount].q2marks;
     
                 cout<<"Enter Assingment # 1 Marks: "<< endl;
                 cin>>arr[stdcount].a1marks;
     
                 cout<<"Enter Assingment # 2 Marks: "<< endl;
                 cin>>arr[stdcount].a2marks;
                 
                 cout<<"Enter MidTerm Marks: "<< endl;
                 cin>>arr[stdcount].midt;
     
                 cout<<"Enter Final Marks: "<< endl;
                 cin>>arr[stdcount].final;
*/
				 stdcount++;
				                
				 system("cls");
}
 void AR::showAll(){
	
	int i=0,t=stdcount;
	
	for(int i=0; i < t  ; i++){
	 
		cout<<"Roll no of index No:"<<i<<" is: " <<arr[i].rollNo<<endl;
	t--;
	}
}
#include "GS.h"

class AR{
  
	GS arr[10];

public:
	void getInput();
	void showAll();
	AR();
	static int stdcount;
};
#include "GS.h"
#include<iostream>
using namespace std;
#include<conio.h>
#include<stdio.h>



GS::GS(){

               rollNo=0;
			//   name=NULL;
              // Quiz Marks Variable
              q1marks=0;
              int q2marks=0;
              // Assingment Marks Variable
               a1marks=0;
               a2marks=0;
              // Midterm  Marks Variable
               midt=0;
              // Final  Marks Variable
              final=0; 
}
#ifndef GS_H
#define GS_H

class GS{
     protected:
		
		     
		     
      public:
		   int rollNo;
			  char name[10];
              // Quiz Marks Variable
              int q1marks;
              int q2marks;
              // Assingment Marks Variable
              int a1marks;
              int a2marks;
              // Midterm  Marks Variable
              int midt;
              // Final  Marks Variable
              int final; 
		  
			  GS();
		 
		 
		  
};

#endif
#include "GS.h"
#include "AR.h"
#include<iostream>
using namespace std;
#include<conio.h>
#include<stdio.h>
 
void showPart(GS []);


int main(){
    
    int option;
AR obj;

	     // Created an object.
    
    // This is menu.
          cout<< "\n\t\t\tGrading System\n\t\t\t**************\n"<< endl;
          cout<< "\n1. Get Input" << endl;
          cout<< "\n2. Find Grade" << endl;
          cout<< "\n3. Show Particular Record" << endl;
          cout<< "\n4. Show All" << endl;
          cout<< "\n5. Exit" << endl;
       //   cout<< "\n\n\nStudent in Record: "<<stdcount<<endl<<endl;             // Counts The Record of Student
        
		  
		  
		  do{
          cin>>option; 
          switch(option){
                         case 1:
							 
							 obj.getInput();
							
                             main(); 
							 break;
                              
                         case 2:
                              
                              break;
                              
                         case 3:
				              break;
                              
                         case 4:
							 obj.showAll();
							  break;
                              
                         case 5:
                              exit(0);                // Quit the program.
                         
                         default:
                                 cout<<"\nERROR! Please select correct option."<<endl;
                                 system("\npause");             // Holds screen.
                                 system("cls");                // Clears the screen
                                 main();                      // Class Main Function when menu fails.
                         }
                         }while(option!=5);
                         
          getch();
        
		  return 0;
    }

Please write complete words. Your txting shorthand makes my brain hurt.

The first thing I see is within your main() in main.cpp, you're recursively calling main(). Don't ever do that; a number of compilers won't even compile it. main() is the entry point from the operating system into your program. Instead, simply move the printing of the menu into the top of the do { ... } while(); loop.

When you declare your static AR::stdcount variable in AR.cpp, assign it an initial value at the same time. E.g. int AR::stdcount = 0;

Avoid using system() calls in your code. There are usually ways to do what you want via function call into a library without executing a separate shell. And specifically avoid coding system("cls"); since the cls command is not portable across shells or operating systems, and even if the user is interacting with the program in a shell/console/terminal, the program should not assume it is the only thing running in, or that it has any control over, the shell/console/terminal. Same goes for system("pause"); -- instead, prompt the user to press a key or enter a value to continue.

In AR::showAll(), why are you incrementing i in the loop-expression, and decrementing t in the loop-body? You're only going to get half the items that way!

At line 15 in GS.cpp, remove the int declaration, qmarks2 is already declared as an int in GS.h. With the extra int, you're creating a temporary local variable which masks the instance member. The temporary variable is destroyed when the constructor returns, and the member with the same name is left uninitialized. But it doesn't look like your code actually uses the GS class for anything, so I don't know why you posted it.

Sorry about my shorthand text, I will try to be more formal in my writing next time!
And yeah i got the problem! thanks alot for your response!
The main mistake was that i was calling the main() function again and again and everytime when the control return back to the starting of body of main() ,the instances/variables/arrays are re created in the memory!
So, I was loosing my data of first index after calling the GetInput() function ,which was the main problem. I got it! Thanks again!

This question has already been answered. Start a new discussion instead.