#include<iostream.h>
#include<fstream.h>
#include<string.h>

class database{
			public:
		    virtual double store_data(void);
		 	virtual void save(ofstream &file);
			virtual double GetPassingMark(int pass);
			virtual void display(void);
			virtual void edit(void);
			protected:
			void data(void);
			
//database(){cout<<"constructing";}
//~database(){cout<<"destructing";}

};

double database::store_data(void)
{
   char code[100];
   double totalmark,laboraty,exam,assignment,sum_assignment;
   int i,no_of_parts,a,pass;
   totalmark=0;
 
     for(i=0;i<7;i++)
	 {
	 cout<<"=======================================================\n";
     cout<<"1.enter the subject code"<<i+1<<"\n";
	 cin>>code;
	 cout<<"2.Enter no of assigments\n:";
	 cin>>no_of_parts;	    
	 sum_assignment=0;
	 for(a=0;a<no_of_parts;a++)
		{
		cout<<"assignment"<<a+1<<":";
	 	cin>>assignment;
		sum_assignment=sum_assignment+assignment;
		}
	
		
	 cout<<"4.labotary\n";
	 cin>>laboraty;
	 cout<<"5.exam\n";

	 cin>>exam;
	 totalmark=sum_assignment+laboraty+exam;
	 GetPassingMark(totalmark);
	 
	 cout<<"=======================================================\n";
	 
	 
	 }
}

void database::save(ofstream &file)
{
	int index,assignment,i,no_of_parts,a;
	char code[100];
	double laboraty,exam,sum_assignment;
	
	for(i=0;i<7;i++)
	{
	file<<"Subject code"<<code<<endl;
	file<<"no of assignments"<<no_of_parts<<endl;
	 file<<"total marks"<<sum_assignment<<endl;
	 
	 	for (a=0;a<no_of_parts;a++)
		{
	save(file);
		}

	
	}

}
double database::GetPassingMark(int pass)
{
	
	cout<<"Your total mark is:"<<pass;
	if(pass>=40)
		{
		cout<<"\nYou have already passed the subject.....oh yeah\n";
		}
	else 
		{
		cout<<"\nMarks required to pass="<<(40-pass)<<endl;
		}
}	 

void database::display(void)
{

}

void database::edit(void)
{
}






int main(void)
{
  database work;
  ofstream file;  
  int option;

cout<<"Please make your selection\n";
cout<<"1.insert data\n";
cout<<"2.edit the stored data\n";
cout<<"3.display the stored result\n";
cout<<"4.exit\n"; 
cin>>option;
switch(option)
	{
		case 1:work.store_data();

			   file.open("D:\\A.txt",ios::app);
			   work.save(file);
			   file.close();
				 break;
		default: break;
		case 2:;
		
		//case 3:break;
		
		//case 4:break;
		
	}
return(0);
}

Edited 6 Years Ago by Nick Evan: Added code-tags

I think you should declare those variables that you are trying to store first of all. You can do that in the scope of the class which would be easier or in function main passing them by reference to function store_data.

The variables you're storing to the TXT file code, no_of_parts, sum_assignment does not contain any value. Those values stored in the function store_data() is locally-scoped. Meaning, they are accessible only inside the function. Therefore, even if you declare the same variable name in your function Save(), the application is not referring to the same variable. For a quick fix, you may consider promoting your variables to global scope.

This article has been dead for over six months. Start a new discussion instead.