- Variables and operators
- Expressions in C++
- Decision structures
- Repetition structures
- Break and Continue statements
XYZ University wants to track students’ admissions. They need a program in C++ which will automate the process.
The program will display the following menu options to user:-
*************************************************************
Please select the program option, in which you want to enter enrollments.
Please enter option 1 for BCS program.
Please enter option 2 for BIT program.
Please enter option 3 for BBA program.
Please enter option 4 for BA program.
*************************************************************
First the user will select the program option, for any invalid option the program should not perform any calculation and display an error message like:-
THE PROGRAM NAME IS INVALID, PLEASE TRY AGAIN.
Press any key to continue…
On pressing any key from the keyboard, the program should start again from the beginning.
Upon entering the valid program option, the program will ask the user to enter students’ enrollment for four years as:-
o Please enter number of students in Year 1.
o Please enter number of students in Year 2.
o Please enter number of students in Year 3.
o Please enter number of students in Year 4.
After entering the valid program option and students’ enrollment data for four years, the department name of the program needs to be displayed. (e.g. for BCS & BIT, the department name needs to be DEPARTMENT OF COMPUTER SCIENCE, for BBA, the department name should be DEPRTAMENT OF BUSINESS ADMINISTRATION while for BA, the department name should be DEPARTMENT OF FINE ARTS.)
Finally, the program will perform some calculations and will display the following information:-
o The number of students in each year.
o The percentage of student’s enrollment in each year against particular program.
o The total number of students in the program.
o Also if the number of students enrolled in a year is greater than 100, then display a message that THE NUMBER OF STUDENTS ENROLLED IN THAT YEAR IS OVER THE LIMIT.
Solution
#include<iostream>
using namespace std;
int main(){
int option ,year_1, year_2, year_3, year_4, sum_of_students;
int check_limit;
cout<<"=========================================================================\n";
cout<<"Please select the program option, in which you want to enter enrollments.\n\n";
cout<<"Please enter option 1 for BCS program\n";
cout<<"Please enter option 2 for BIT program\n";
cout<<"Please enter option 3 for BBA program\n";
cout<<"Please enter option 4 for BA program\n";
cout<<"=========================================================================\n\n";
do {
cout<<"Please enter program option: ";
cin>>option;
if (option > 0 && option <= 4){
cout<<"Please enter number of students in Year 1: ";
cin>>year_1;
if (year_1 > 100){
check_limit = 1;
}
cout<<"Please enter number of students in Year 2: ";
cin>>year_2;
if (year_2 > 100){
check_limit = 2;
}
cout<<"Please enter number of students in Year 3: ";
cin>>year_3;
if (year_3 > 100){
check_limit = 3;
}
cout<<"Please enter number of students in Year 4: ";
cin>>year_4;
if (year_4 > 100){
check_limit = 4;
}
cout<<"\n\n";
if(option == 1 || option == 2){
cout<<"*************DEPARTMENT OF COMPUTER SCIENCE*************\n";
} else if(option == 3){
cout<<"*************DEPRTAMENT OF BUSINESS ADMINISTRATION*************\n";
} else {
cout<<"*************DEPARTMENT OF FINE ARTS*************\n";
}
cout<<"\n";
cout<<"The number of students in Year 1 is: "<<year_1<<"\n";
cout<<"The number of students in Year 2 is: "<<year_2<<"\n";
cout<<"The number of students in Year 3 is: "<<year_3<<"\n";
cout<<"The number of students in Year 4 is: "<<year_4<<"\n";
cout<<"\n";
sum_of_students = year_1+year_2+year_3+year_4;
double year_1_percentage = (double)year_1/sum_of_students*100;
cout<<"The percentage of students in year 1 is: "<<year_1_percentage<<"%\n";
double year_2_percentage = (double)year_2/sum_of_students*100;
cout<<"The percentage of students in year 2 is: "<<year_2_percentage<<"%\n";
double year_3_percentage = (double)year_3/sum_of_students*100;
cout<<"The percentage of students in year 3 is: "<<year_3_percentage<<"%\n";
double year_4_percentage = (double)year_4/sum_of_students*100;
cout<<"The percentage of students in year 4 is: "<<year_4_percentage<<"%\n";
cout<<"\n";
cout<<"Total number of student in program is: "<<sum_of_students<<"\n";
cout<<"\n";
cout<<"THE NUMBER OF STUDENTS ENROLLED IN YEAR "<<check_limit;
cout<<" IS OVER THE LIMIT:\n";
}else {
cout<<"THE PROGRAM NAME IS INVALID, PLEASE TRY AGAIN.\n";
system("pause");
}
}while(option > 4 || option < 1);
}
0 Comments