C++ PRACTICAL 2
Q] Write a program to prepare information of students during admission process. The
program must accept the total count of admitted students from the operator. For every student
the program must accept first name, middle name, surname, SAP No, percentage of pre-
qualifying examination, mobile no, date of birth, year of admission. Design a program which
will be menu driven. The program must provide following features:
1) To print information of all students.
2) To accept SAP No from the operator and print information of related student.
3) To count no. of students having distinction (=>70), first class (=>60 or <70), second class
(=>40 or <60).
4) The program must accept surname from operator and print all the name of students having
same surname.
INPUT:
//Abubaker Bhola M028 57502240028//
#include <iostream>
using namespace std;
int i;
class student
public:
string firstname, middlename, lastname;
double sapno, mobileno;
float percentage;
int dobdate, dobmonth, dobyear, admissionyear;
};
int main()
int v;
class student s[100];
int noofstudents;
cout<<endl<<"Welcome to SVKMs Shri Bhagubhai Mafatlal Polytechnic"<<endl;
cout<<endl<<"Enter number of students admitted:";
cin>> noofstudents;
/*program to accept information of admitted students*/
for (i=0; i<=noofstudents-1; i++)
cout<<endl<<"Enter the first name of student no. " << i+1<<" ";
cin>>s[i].firstname;
cout<<endl<<"Enter the middle name of student no. "<< i+1<<" ";
cin>>s[i].middlename;
cout<<endl<<"Enter the last name of student no. "<< i+1<<" ";
cin>>s[i].lastname;
cout<<endl<<"Enter the SAP number of student no. "<< i+1<<" ";
cin>>s[i].sapno;
cout<<endl<<"Enter the mobile number of student no. "<< i+1<<" ";
cin>>s[i].mobileno;
cout<<endl<<"Enter the percentage of student no. "<< i+1<<" in the previous year ";
cin>>s[i].percentage;
cout<<endl<<"Enter the date of birth of student no. "<< i+1<<" ";
cin>>s[i].dobdate;
cout<<endl<<"Enter the month of birth of student no. "<< i+1<<" ";
cin>>s[i].dobmonth;
cout<<endl<<"Enter the year of birth of student no. "<< i+1<<" ";
cin>>s[i].dobyear;
cout<<endl<<"Enter the year of admission of student no. "<< i+1<<" ";
cin>>s[i].admissionyear;
//program to exercise menu driven choices//
start:
cout<<endl<<"Please select any one option"<<endl;
cout<<endl<<"Option 1: Print information of all admitted students";
cout<<endl<<"Option 2: Print information of particular student by entering SAP number";
cout<<endl<<"Option 3: To count number of students with distinction ( >=70%), first class (>=60%), second
class (>=50%), pass class (>=40%) ";
cout<<endl<<"Option 4: Find all students according to the last name entered by operator";
int option;
cout<<endl<<"Enter your option :";
cin>>option;
start:
switch(option)
case 1:
cout<<endl<<"The information of all admitted "<<noofstudents<< " students is as per below"<<endl;
for (i=0; i<=noofstudents-1; i++)
cout<<endl<<"The information of student no. : "<< i+1<<endl;
cout<<endl<<" Name of student : "<<s[i].firstname<<" " <<s[i].middlename<<" "<<s[i].lastname;
cout<<endl<<" SAP number : "<<s[i].sapno;
cout<<endl<<"Mobile number : "<<s[i].mobileno;
cout<<endl<<"Percentage : "<<s[i].percentage;
cout<<endl<<"Date of birth (DD/MM/YYYY) : "<<s[i].dobdate<<" / "<<s[i].dobmonth<<" / "<<s[i].dobyear;
cout<<endl<<"Year of admission : "<<s[i].admissionyear<<endl;
break;
case 2:
double studsapno;
cout<<"Enter SAP number : ";
cin>>studsapno;
for (i=0; i<=noofstudents-1; i++)
{
if(s[i].sapno==studsapno)
cout<<endl<<"The information of student with SAP no. : "<< studsapno <<endl;
cout<<endl<<" Name of student : "<<s[i].firstname<<" " <<s[i].middlename<<" "<<s[i].lastname;
cout<<endl<<" SAP number : "<<s[i].sapno;
cout<<endl<<"Mobile number : "<<s[i].mobileno;
cout<<endl<<"Percentage : "<<s[i].percentage;
cout<<endl<<"Date of birth (DD/MM/YYYY) : "<<s[i].dobdate<<" / "<<s[i].dobmonth<<" / "<<s[i].dobyear;
cout<<endl<<"Year of admission : "<<s[i].admissionyear<<endl;
break;
case 3:
int distinction, first, second, pass;
distinction=0;
first=0;
second=0;
pass=0;
for (i=0; i<=noofstudents-1; i++)
if((s[i].percentage<100||s[i].percentage==100)&&(s[i].percentage>70||s[i].percentage==70))
distinction++;
if(s[i].percentage<70&&(s[i].percentage>60||s[i].percentage==60))
first++;
}
if(s[i].percentage<60&&(s[i].percentage>50||s[i].percentage==50))
second++;
if(s[i].percentage<50&&(s[i].percentage>40||s[i].percentage==40))
pass++;
cout<<endl<<"Number of students with distinction : "<<distinction;
cout<<endl<<"Number of students with first class : "<<first;
cout<<endl<<"Number of students with second class : "<<second;
cout<<endl<<"Number of students with pass class : "<<pass;
break;
case 4:
string studlast;
cout<<"Enter last name : ";
cin>>studlast;
for (i=0; i<=noofstudents-1; i++)
if(s[i].lastname==studlast)
cout<<endl<<" Name of student : "<<s[i].firstname<<" " <<s[i].middlename<<" "<<s[i].lastname;
break;
v=v+1;
goto start;
return 0;
OUTPUT:
Q] Write a program using classes and objects to prepare information of books in a library. The program must
accept the information every for newly purchased book such as:
a) Name of book
b) Name of author
c) Name of publisher
d) Book ID No
e) Year of edition
f) Name of relevant branch
The program must be menu driven. The program must have following features:
1) The program must accept name of book and inform the operator regarding no. of copies available.
2) The program must accept the book ID No. and print the information of that book.
3) The program must calculate the total no. of books available in every department.
4) The program must accept the year of edition form the operator and must calculate total no. of books
available for given year of edition.
INPUT:
#include <iostream>
#include <string>
using namespace std;
int i;
class Book
{
public:
string name, author, publisher, branch;
int bookid, year;
};
int main()
int k=1;
start_loop: // <-- Goto label for menu
class Book b[100];
int noofbook;
cout << endl << "Welcome to Library Management System" << endl;
cout << endl << "Enter number of books to add: ";
cin >> noofbook;
for(i=0;i<=noofbook-1;i++)
cout << endl << "Enter the name of book no. " << i + 1 << " ";
cin >> b[i].name;
cout << endl << "Enter the author name of book no. " << i + 1 << " ";
cin >> b[i].author;
cout << endl << "Enter the publisher name of book no. " << i + 1 << " ";
cin >> b[i].publisher;
cout << endl << "Enter the Book id number of book no. " << i + 1 << " ";
cin >> b[i].bookid;
cout << endl << "Enter the Year of Edition of book no. " << i + 1 << " ";
cin >> b[i].year;
cout << endl << "Enter the relevant branch of book no. " << i + 1 << " ";
cin >> b[i].branch;
cout << endl << "Please select any one option" << endl;
cout << endl << "Option 1: Check copies available: ";
cout << endl << "Option 2: Print information of book id number: ";
cout << endl << "Option 3: Branch : ";
cout << endl << "Option 4: Books from given year : ";
int option;
start:
cout << endl << "Enter your option : "; cin >> option;
switch (option)
case 1:
string bookname;
cout << "Enter Book Name-";
cin >> bookname;
int booknamecount=0;
for (i=0; i<=noofbook-1; i++)
if(b[i].name==bookname)
booknamecount++;
cout << endl << "Copies available for " << bookname << " are " << booknamecount;
break;
case 2:
int searchid;
cout << "Enter Book id to search: ";
cin >> searchid;
int found = 0;
for (i = 0; i < noofbook; i++)
{
if (b[i].bookid == searchid)
cout << "Book Name: " << b[i].name << endl;
cout << "Author: " << b[i].author << endl;
cout << "Publisher: " << b[i].publisher << endl;
cout << "Book id : " << b[i].bookid << endl;
cout << "Year: " << b[i].year << endl;
cout << "Branch: " << b[i].branch << endl;
found = 1;
if (found == 0)
cout << "Book id not found!" << endl;
break;
case 3:
int mech, civil, electric;
mech=0;
civil=0;
electric=0;
for (i=0; i<=noofbook-1; i++)
if(b[i].branch=="MECHANICAL"||b[i].branch=="mechanical"||b[i].branch=="Mechanical")
mech++;
if(b[i].branch=="CIVIL"||b[i].branch=="civil"||b[i].branch=="Civil")
{
civil++;
if(b[i].branch=="ELECTRICAL"||b[i].branch=="electrical"||b[i].branch=="Electrical")
electric++;
cout<<endl<<"Number of books from Mechanical : "<<mech;
cout<<endl<<"Number of books from Civil : "<<civil;
cout<<endl<<"Number of books from Electrical : "<<electric;
break;
case 4:
int book, editionyear;
cout << "Enter year of edition required: ";
cin>>editionyear;
cout<<endl;
book=0;
for(i=0; i<=noofbook-1; i++)
if(b[i].year == editionyear)
book++;
cout<<endl;
cout<<"Number of books from"<< editionyear<<"is : " <<book;
break ;
goto start;
return 1;
}
OUTPUT: