#include<iostream.h>
#include<fstream.h>
class studentinfo
{
private:/*Creating Private Data Members */
char* VUID;
char* campusID;
char* Studentname;
char* Fathername;
public:
void Storefile();/* Function to Store Data in the File*/
char Display();/*Function to Read and then Display Data from the File*/
studentinfo(char*, char*, char*, char*);/*Constructor to initialize Data Members*/
~studentinfo();
};
/* Constructor Defined Here*/
studentinfo::studentinfo(char* VUID, char* campusID, char* Studentname, char* Fathername)
{
cout<<"Parameterized Contructor is Called"<<endl<<endl;
}
/*Destructor Defined Here*/
studentinfo::~studentinfo()
{
cout<<"Destructor Called for destruction of the object"<<endl;
system("pause");
}
/*Function to Store Data in the File Defined here*/
void studentinfo::Storefile()
{
ofstream re;
re.open("record.txt");
if(!re)/*Error Checking Mechanism*/
{
cout<<"Error Reading File"<<endl;
}
re<<VUID<<endl<<campusID<<endl<<Studentname<<endl<<Fathername<<endl;/*Using Global Pointer Variables to Store data in the File*/
cout<<"All the Data Members are Stored in a File"<<endl<<endl;
re.close();
}
/*Function to Read and then Display the data in the File is definde here */
char studentinfo::Display()
{
char output[100];/*Array to store and display the data*/
ifstream reh;
reh.open("record.txt");
if(!reh)
{
cout<<"Error Reading File"<<endl;
}
cout<<"Following is My Data"<<endl<<endl;
while(!reh.eof()){
reh.getline(output, 100, '\n');/*Reading the data and storing it in the 'output' array line by line*/
cout<<output<<endl;
}
reh.close();
}
/*Main Function starting here*/
main()
{
studentinfo s1("mc123456789", "PMMK08", "xxxx xxxxx xxxxx","xxxx xxxxxx xxxxxx");/*Object Created and Initialized by constructor calling*/
s1.Storefile();/*Function Call*/
s1.Display();/*Function Call*/
system("pause");
}
sireiz
0
Junior Poster in Training
Recommended Answers
Jump to PostYou never set the values
VUID campusID Studentname Fathername
in the student object when you create it.While I am here, I would be remiss if I did not point out that you are using mutant pre-standard C++ from about twenty years ago. Since 1998, we have used
namespace
s, C++ …
Jump to PostYup, as Moschops has said, it's because your constructor is not initialising anything. Which is what I said in my post in your other thread. You are taking in the four parameters, but you still aren't doing anything with them. You need to use the passed-in parameters to initialise the …
All 5 Replies
Moschops
683
Practically a Master Poster
Featured Poster
JasonHippy
739
Practically a Master Poster
sireiz
0
Junior Poster in Training
JasonHippy
739
Practically a Master Poster
sireiz
0
Junior Poster in Training
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.