Assignment No.3 & 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Group Members:

• Ameer Hamza 22201018 - 045


• Yahya Iftikhar 22201018 - 021
• Hafiz Muhammad Ahmed 22201018 - 015
• Shameel Saifi 22201018 - 011
• Adeel Ali Yousaf 22201018 – 042
(ADP – Computer Science, 2nd Semester)
Instructor: Sir Faheem Khan

❖ Assignment No. 3 & 4:


❖ Input:

#include<iostream>
#include<fstream>
#include <cstring>

using namespace std;


class student
{
public:
string id,fname,lname,contact,gender,blood,course,age;
float marks, obmarks, percentage;

void setdata()
{
fstream file;
cout << endl;
cout << "\xB2\xB2\xB2\xB2\xB2\xB2 Admission Form
\xB2\xB2\xB2\xB2\xB2\xB2";
cout << "\n\nStudent ID: ";
cin.ignore();
getline(cin,id);
cout << "\nFirst Name: ";
getline(cin, fname);
cout << "\nLast Name: ";
getline(cin,lname);
cout << "\nAge: ";
getline(cin,age);
cout << "\nGender: ";
getline(cin,gender);
cout<<"\nBlood Group: ";
getline(cin,blood);
cout<<"\nContact no. ";
getline(cin,contact);
cout << "\nCourse / Program: ";
getline(cin,course);
cout << "Data has been saved Successfully . . . .\n";
system("pause");

file.open("data.txt", ios::app|ios::out);
file << id << "\t\t" << fname << "\t\t" << lname << "\t\t" << age << "\t\t" <<
gender << "\t\t"<< blood << "\t\t" << contact << "\t\t" << course << endl;
file.close();
}
void searchData()
{
fstream file;
int found = 0;
file.open("data.txt", ios::in);
if (!file) {
cout << "File does not Exist . . . . " << endl;
} else {
string rollno;
cout<<endl;
cout << "\xB2\xB2\xB2\xB2\xB2\xB2 Search Form
\xB2\xB2\xB2\xB2\xB2\xB2";
cout << "\n\nStudent ID: ";
cin >> rollno;
file >> id >> fname >> lname >> age >> gender >> blood >> contact
>> course;
while (!file.eof()) {
if (rollno == id) {
display();
found++;
}
file >> id >> fname >> lname >> age >> gender >> blood >>
contact >> course;

}
file.close();
}
}

void display()
{
cout << "\n\xB1\xB1\xB1\xB1\xB1 Student Details
\xB1\xB1\xB1\xB1\xB1\xB1 ";
cout<<"\n\nStudent Name: "<<fname<<" "<<lname;
cout<<"\nStudent Age: "<<age;
cout<<"\nStudent Gender: "<<gender;
cout<<"\nStudent Blood Group: "<<blood;
cout<<"\nStudent Contact no. "<<contact;
cout<<"\nCourse Studying in: "<<course;
cout<<"\n\n";
system("pause");
}

void result()
{
fstream file;
int found = 0;
file.open("data.txt", ios::in);
if (!file) {
cout << "File does not Exist . . . . " << endl;
} else {
string rollno;
cout<<endl;
cout << "\xB2\xB2\xB2\xB2\xB2\xB2 Result Form
\xB2\xB2\xB2\xB2\xB2\xB2";
cout << "\n\nEnter Student ID: ";
cin >> rollno;
file >> id >> fname >> lname >> age >> gender >> blood >> contact
>> course;
while (!file.eof()) {
if (rollno == id) {
cout<<"\nStudent Name: "<<fname<<"
"<<lname<<endl;
cout<<"\nCourse Studying: "<<course<<endl;
cout<<"\nEnter Total Marks: ";
cin>>marks;
cout<<"\nEnter Obtained Marks: ";
cin>>obmarks;
percentage = (obmarks*100)/marks;
cout<<"\nPrecentage Obtained: "<<percentage<<"
%"<<endl;
if(percentage>=50) {
cout<<"\nCongratulation! "<<fname<<". You
have been Promoted!."<<endl;
} else {
cout<<"Better Luck Next Time!.";
}
system("pause");
found++;
}
file >> id >> fname >> lname >> age >> gender >> blood >>
contact >> course;

}
file.close();
}
}
void dlt()
{
fstream file, file1;
int found = 0;
string roll;
file.open("data.txt", ios::in);
if (!file) {
cout << "\n\t\t\tNo File Existed . . . . ";
file.close();
} else {
cout << "\nEnter Student ID: ";
cin >> roll;
file1.open("file.txt", ios::app | ios::out);
file >> id >> fname >> lname >> age >> gender >> blood >> contact
>> course;
while (!file.eof()) {
if (roll != id) {
file1 << id << "\t\t" << fname << "\t\t" << lname << "\t\t" <<
age << "\t\t" << gender << "\t\t"<< blood << "\t\t" << contact << "\t\t" << course << endl;
} else {
found++;
cout << "\n\xB1\xB1\xB1\xB1\xB1 Student Record has
Been Deleted \xB1\xB1\xB1\xB1\xB1\xB1\n\n ";
system("pause");
}
file >> id >> fname >> lname >> age >> gender >> blood >>
contact >> course;
}
if (found == 0) {
cout << "\n\xB1\xB1\xB1\xB1\xB1 Roll no. / ID does not exist
\xB1\xB1\xB1\xB1\xB1\xB1\n\n";
system("pause");
}
file1.close();
file.close();
remove("data.txt");
rename("file.txt", "data.txt");
}
}

void menu()
{
system("cls");
cout << endl;
int op;
cout << "\n\xB2\xB2\xB2\xB2\xB2\xB2 Student Management
\xB2\xB2\xB2\xB2\xB2\xB2\n";
cout << "\n1.Admission";
cout << "\n2.Result";
cout << "\n3.Search";
cout << "\n4.Delete";
cout << "\n5.Exit\n";
cout << "\n\xB1\xB1\xB1\xB1\xB1\xB1\xB1\xB1\xB1 Enter(1 - 5)
\xB1\xB1\xB1\xB1\xB1\xB1\xB1\xB1\xB1: ";
cin >> op;

switch (op) {
case 1:
system("cls");
setdata();
menu();
break;

case 2:
system("cls");
result();
menu();
break;

case 3:
system("cls");
searchData();
menu();
break;

case 4:
system("cls");
dlt();
menu();
break;

case 5:
exit(0);
menu();
break;
}
}
student()
{
menu();
}
};

int main()
{
student s;
return 0;
}
❖ Outputs:

You might also like