You are on page 1of 11

Date: 15th May 2017

Computer Programming
Final Semester Project

ALI ZAHID BHATTY (130667)


AMEER UL HAQ (130721)

SAAD USMAN (130727)


BEMTS-2B

BE MECHATRONICS (2013 - 2017)

Miss Fatima Noor


Lab Instructor

DEPARTMENT OF MECHTRONICS ENGINEERING


FACULTY OF ENGINEERING
AIR UNIVERSITY, ISLAMABAD
PROJECT:
The objective of the management system is to collect the student information and represent it in a
proper format. Program will require to have a structure of students with data members as Name,
Date of Birth, Age, Address, Courses. Your program will allocate a grade against each course on
the basis of marks obtained.
Your program should be menu driven with the options to enter student information.

1. Add new record


2. Remove record
3. Update Record
4. Search for particular student

Code
#include <iostream> //Initializing
#include <cstring>
#include <istream>
#include <string>
using namespace std;
struct student //Structure types
{
string name;
string dob;
int age;
string address;
string courses;
char grade;
string data="Data is removed";
};
int main ()
{
student s1,s2,s3; //3 student records
cout<<"Please select an option"<<endl;
cout<<"1. Add new record of the student"<<endl;
cout<<"2. Remove the record"<<endl;
cout<<"3. Update the record"<<endl;
cout<<"4. Search for Particular student"<<endl;
int n,n11,n22;
cin>>n;
if (n==1) //1st student new record
{
int c1;
cout<<"Now you have to enter a new record of a student"<<endl;
cout<<"Enter student's name : ";
cin>>s1.name;
cout<<endl;
cout<<"Enter the date of birth : ";
getline(cin,s1.dob);
cout<<endl;
cout<<"Enter age : ";
cin>>s1.age;
cout<<endl;
cout<<"Enter the address : ";
getline(cin,s1.address);
cout<<endl;
cout<<"Enter your number of courses : "; //Entering number of
courses and assigning Grades
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
cin>>s1.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++) //Assigning Grades of all courses
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='F';

cout<<"For 2nd Student : "<<endl; //For 2nd Student


cout<<"1. Add new record of the student"<<endl;
cout<<"2. Remove the record"<<endl;
cout<<"3. Update the record"<<endl;
cin>>n11;
if (n11==1)
{
int c1;
cout<<"Now you have to enter a new record of a student"<<endl;
cout<<"Enter student's name : ";
cin>>s2.name;
cout<<endl;
cout<<"Enter the date of birth : ";
getline(cin,s2.dob);
cout<<endl;
cout<<"Enter age : ";
cin>>s2.age;
cout<<endl;
cout<<"Enter the address : ";
getline(cin,s2.address);
cout<<endl;
cout<<"Enter your number of courses : ";
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
//Assigning grades to all courses
cin>>s2.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++)
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='F';

cout<<"For 3rd Student : "<<endl; //For 3rd Student


cout<<"1. Add new record of the student"<<endl;
cout<<"2. Remove the record"<<endl;
cout<<"3. Update the record"<<endl;
cin>>n22;
if (n22==1)
{
int c1;
cout<<"Now you have to enter a new record of a student"<<endl;
cout<<"Enter student's name : ";
cin>>s3.name;
cout<<endl;
cout<<"Enter the date of birth : ";
getline(cin,s3.dob);
cout<<endl;
cout<<"Enter age : ";
cin>>s3.age;
cout<<endl;
cout<<"Enter the address : ";
getline(cin,s3.address);
cout<<endl;
cout<<"Enter your number of courses : ";
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
cin>>s3.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++)
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='F';
}
}
}

if (n==2) //Removing record of students


{
int n33;
cout<<"Which student's record you want to remove ? "<<endl;
cout<<"Student 1 ?\n"<<"Student 2 ?\n"<<"Student 3 ?\n"<<"Student 4 ?"<<endl;
cin>>n33;
if (n33==1) //Removing record for 1st student
{
cout<<"Record is removed for student 1";
s1.name=s1.data;
s1.dob=s1.data;
s1.address=s1.data;
s1.courses=s1.data;
}
else if (n33==2)
{
cout<<"Record is removed for stude nt 2"; //For 2nd student
s2.name=s2.data;
s2.dob=s2.data;
s2.address=s2.data;
s2.courses=s2.data;
}
else if (n33==3)
{
cout<<"Record is removed for student 3"; //For 3rd student
s1.name=s3.data;
s1.dob=s3.data;
s1.address=s3.data;
s1.courses=s3.data;
}
}
if (n==3)
{

cout<<"Upgrade data of Student 1?\n"<<"Upgrade data of Student 2?\n"<<"Upgrade data


of Student 3?"<<endl;
int n44;
cin>>n44;
if (n44==1) //Upgrading student 1
{
cout<<"What you want to upgrade? ";
cout<<"1. Name ? "<<endl;
cout<<"2. Date of Birth ?"<<endl;
cout<<"3. Age ?"<<endl;
cout<<"4. Address ?"<<endl;
cout<<"5. No. of courses ?"<<endl;
int n2;
cin>>n2;
if (n2==1)
{
cout<<"Enter student's name : ";
cin>>s1.name;
cout<<endl;
}
if (n2==2)
{
cout<<"Enter the date of birth : ";
getline(cin,s1.dob);
cout<<endl;
}
if (n2==3)
{
cout<<"Enter age : ";
cin>>s1.age;
cout<<endl;
}
if (n2==4)
{
cout<<"Enter the address : ";
getline(cin,s1.address);
cout<<endl;
}
if (n2==5)
{
int c1;
cout<<"Enter your number of courses : ";
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
cin>>s1.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++)
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s1.grade='F';
}
}

else if (n44==2) //Upgrading student 2


{
cout<<"What you want to upgrade? ";
cout<<"1. Name ? "<<endl;
cout<<"2. Date of Birth ?"<<endl;
cout<<"3. Age ?"<<endl;
cout<<"4. Address ?"<<endl;
cout<<"5. No. of courses ?"<<endl;
int n2;
cin>>n2;
if (n2==1)
{
cout<<"Enter student's name : ";
cin>>s2.name;
cout<<endl;
}
if (n2==2)
{
cout<<"Enter the date of birth : ";
getline(cin,s2.dob);
cout<<endl;
}
if (n2==3)
{
cout<<"Enter age : ";
cin>>s2.age;
cout<<endl;
}
if (n2==4)
{
cout<<"Enter the address : ";
getline(cin,s2.address);
cout<<endl;
}
if (n2==5)
{
int c1;
cout<<"Enter your number of courses : "; //Assigning new grades to new courses
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
cin>>s2.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++)
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s2.grade='F';
}
}
else if (n44==3) //Upgrading student 3 record
{

cout<<"What you want to upgrade? ";


cout<<"1. Name ? "<<endl;
cout<<"2. Date of Birth ?"<<endl;
cout<<"3. Age ?"<<endl;
cout<<"4. Address ?"<<endl;
cout<<"5. No. of courses ?"<<endl;
int n2;
cin>>n2;
if (n2==1)
{
cout<<"Enter student's name : ";
cin>>s3.name;
cout<<endl;
}
else if (n2==2)
{
cout<<"Enter the date of birth : ";
getline(cin,s3.dob);
cout<<endl;
}
else if (n2==3)
{
cout<<"Enter age : ";
cin>>s3.age;
cout<<endl;
}
else if (n2==4)
{
cout<<"Enter the address : ";
getline(cin,s3.address);
cout<<endl;
}
else if (n2==5)
{
int c1;
cout<<"Enter your number of courses : ";
cin>>c1;
int marks [5];
for (int i=0;i<=c1;i++)
{
cout<<"Enter the name of "<<i+1<<" course : ";
cin>>s3.courses[i];
cout<<"Now enter the marks : ";
cin>>marks[i];
}
for (int i=0;i<=c1;i++)
{
if (marks[i]>84 && marks[i]<101)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='A';
}
else if (marks[i]>69 && marks[i]<85)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='B';
}
else if (marks[i]>59 && marks[i]<70)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='C';
}
else if (marks [i]>49 && marks[i]<61)
{
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='D';
}
else
cout<<"Your grade in "<<i+1<<" course is : ";
s3.grade='F';
}
}
if (n==4) //Removing the record
{
cout<<"1. Student 1 ? "<<endl;
cout<<"2. Student 2 ? "<<endl;
cout<<"3. Student 3 ? "<<endl;
int n3;
cin>>n3;
if (n3==1) //For 1st student
{
cout<<s1.name<<endl;
cout<<s1.dob<<endl;
cout<<s1.age<<endl;
cout<<s1.address<<endl;
}
else if (n3==2) //For 2nd student
{
cout<<s2.name<<endl;
cout<<s2.dob<<endl;
cout<<s2.age<<endl;
cout<<s2.address<<endl;
}
else if (n3==3) //For 3rd student
{
cout<<s3.name<<endl;
cout<<s3.dob<<endl;
cout<<s3.age<<endl;
cout<<s3.address<<endl;
}

}
}

return 0; //Return value 0


}

Code Explanation
• Main Screen appears to have 4 options.
1. New Record
2. Remove the record
3. Upgrade record
4. Search for particular student
If user select (1), program ask the user to enter the record of student 1,2 and 3 respectively.
If user select (2), program ask the user to remove the record of student 1,2 and 3 respectively.
If user select (3), program ask the user to update the record of student 1,2 and 3 respectively.
If user select (4), program ask the user to search for the particular student and displays his data.

• If and else statements are used for selecting an option.


• Structure variable array can also be used to avoid if else conditions.
• User will have the full choice to select between student 1,2 and 3 and update, remove the
record.
• The main problem I was facing was an error from the syntax “getline(cin, )”.I already have
consulted Sir Atif for this and he said to add a particular library of string. Despite of using
that, error remains. (in Eclipse)

You might also like