BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   BsTS 2nd Semester (http://bzupages.com/forumdisplay.php?f=243)
-   -   Filling in oop c++ (http://bzupages.com/showthread.php?t=1559)

T-INFECTION 11-12-2008 09:54 AM

Filling in oop c++
 
#include
#include
#include
using namespace std;
class Student
{
private:
int rollno;
char name[30];
double marks;
public:
Student()
{
rollno = 0;
strcpy(name, "");
marks = 0;
}
void InputData()
{
cout << "Enter the rollno:";
cin >> rollno;
cin.ignore (256, '\n');
cout << "Enter the name: ";
cin.getline(name, 30);
cout << "Enter the marks: ";
cin >> marks;
}
void DisplayData()
{
cout << "Rollno: " << rollno << endl;
cout << "Name: " << name << endl;
cout << "Marks: " << marks << endl;
}
};
void CreateFile()
{

ofstream os("Student.dat",ios::out|ios::binary);
if (!os)
{
cout << "Unable to create file" << endl;
exit(1);
}
cout << "Successfully File Created" << endl;
}
void AddRecord()
{
Student s;

ofstream os("Student.dat",ios::app|ios::binary);
if (!os)
{
cout << "Unable to open file" << endl;
exit(1);
}
int n;
cout << "Enter the no of records to store:";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "Enter the student Info" << endl;
s.InputData();
os.write((char *) &s, sizeof(s));
cout << "Record Stored Successfully" << endl;
}
os.close();
} // end of Add Record
void DisplayRecord()
{
Student s;
/* Statement to read records from student file */
ifstream is("Student.dat",
ios::in|ios::binary);
if (!is)
{
cout << " Unable to open file or File not found" << endl;
exit(1);
}
while (!is.eof())
{
is.read((char*) &s, sizeof(s));
if (!is.eof())
s.DisplayData();
}
is.close();
} // end of Dislay Record
int main()
{
int opt;
while (1)
{
cout << "!!!!!!!Student Database System!!!!!!!" << endl;
cout << "1: Create Student File " << endl;
cout << "2: Add Records " << endl;
cout << "3: Display Records " << endl;
cout << "4: Exit " << endl;
cout << "Ente the option: ";
cin >>opt;
if (opt == 1)
CreateFile();
else if (opt == 2)
AddRecord();
else if (opt == 3)
DisplayRecord();
else if (opt == 4)
break;
else
cout << "Invalid option" << endl;
} // end of while loop

return 0;
}
//M.ATTIQUE ATTA
//333-4671561


:huh:

bonfire 19-11-2010 01:57 AM

Re: Filling in oop c++
 
Thanks


All times are GMT +5. The time now is 06:14 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.