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...!


using namespace std;
int AR::stdcount;

void AR::getInput(){
					cout<<"Enter Roll NO:"<<endl;

				 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;	
				 cout<<endl<<"Enter Name:"<<endl;

                 cout<<"Enter Quiz # 1 Marks "<< endl;
                 cout<<"Enter Quiz # 2 Marks: "<< endl;
                 cout<<"Enter Assingment # 1 Marks: "<< endl;
                 cout<<"Enter Assingment # 2 Marks: "<< endl;
                 cout<<"Enter MidTerm Marks: "<< endl;
                 cout<<"Enter Final Marks: "<< endl;
 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;
#include "GS.h"

class AR{
	GS arr[10];

	void getInput();
	void showAll();
	static int stdcount;
#include "GS.h"
using namespace std;


			//   name=NULL;
              // Quiz Marks Variable
              int q2marks=0;
              // Assingment Marks Variable
              // Midterm  Marks Variable
              // Final  Marks Variable
#ifndef GS_H
#define GS_H

class GS{
		   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; 

#include "GS.h"
#include "AR.h"
using namespace std;
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
                         case 1:
                         case 2:
                         case 3:
                         case 4:
                         case 5:
                              exit(0);                // Quit the program.
                                 cout<<"\nERROR! Please select correct option."<<endl;
                                 system("\npause");             // Holds screen.
                                 system("cls");                // Clears the screen
                                 main();                      // Class Main Function when menu fails.
		  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.