Last active
May 31, 2020 17:24
-
-
Save swaaz/901bf653a9ab06a68cc39977f22a42be to your computer and use it in GitHub Desktop.
Programming apti Assignment- 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1: Consider the scenario where 6 professors are training a bunch of 63 students on 6 programming languages(Java, C, Python, CPP, C_Hash, R). | |
// Deploy the scenario in the interactive mode and perform several tasks using the constraints and conditions below, | |
// Student has following properties: | |
// Attributes -> name, age, usn, cgpa(avg. of 6 programming language scores), favProfName, favPrgLang | |
// Methods -> getters() and setters() for reading and retrieving data, readStudent() for deploying setters, showStudent() for displaying student details by deploying getters. | |
// Professor has following properties: | |
// Attributes -> name, age, profId, salary, favStudentName, progLangHandling, rating | |
// Methods -> getters() and setters() for reading and retrieving data, readProf() by deploying setters, showProf() for displaying details by deploying getters. | |
// Implement the following functions, | |
// * Function to find top scorer of individual programming language by taking language as input | |
// * Function to display the student’s favourite Professor’s details by taking student name as input(friend function as bridge between two classes) | |
// * Function to provide rating to professors by taking professor id as input parameter(Only one chance for each student to rate each of 6 professors) -> 1: Good 2: Better 3: Best 4: Excellent 5: Awesome | |
// * Function to find top rated professor | |
// * Function to find top scorer of class | |
// * Function to find the average score of class (Overload + operator to add the individual student cgpa)cout<<"Enter the number of students : "; | |
// * Show the count of students who have preferred a particular programming language by taking it as input | |
// Note: | |
// * Data Members have private access specifier | |
// * Additional attributes and methods to individual classes can be added if necessary | |
// * Implement the tasks in menu driven fashion | |
// * Program has to be interactive and soft coded | |
#include<stdio.h> | |
#include<iostream> | |
#include<string> | |
#include<ctype.h> | |
#include<bits/stdc++.h> | |
using namespace std; | |
int n_stud,n_prof; | |
class Student | |
{ | |
private: | |
string name; | |
int age; | |
string USN; | |
float CGPA; | |
string fav_prof; | |
string fav_lang; | |
int Java; | |
int C; | |
int Python; | |
int CPP; | |
int C_Hash; | |
int R; | |
public: | |
void read_Student(); | |
void show_Student(); | |
int calc_cgpa(); | |
Student operator+(Student &); | |
// Getters() | |
int get_age(); | |
string get_name(); | |
string get_USN(); | |
float get_CGPA(); | |
string get_fav_prof(); | |
string get_fav_lang(); | |
int get_Java(); | |
int get_C(); | |
int get_Python(); | |
int get_CPP(); | |
int get_C_Hash(); | |
int get_R(); | |
// Setters() | |
void set_name(string name); | |
void set_age(int age); | |
void set_USN(string USN); | |
void set_CGPA(float CGPA); | |
void set_fav_prof(string fav_prof); | |
void set_fav_lang(string fav_lang); | |
void set_Java(int x); | |
void set_C(int x); | |
void set_Python(int x); | |
void set_CPP(int x); | |
void set_C_Hash(int x); | |
void set_R(int x); | |
// friend void search_stud(string name); | |
}; | |
Student s[63]; | |
void Student::read_Student() | |
{ | |
string name; | |
int age; | |
string USN; | |
float CGPA; | |
string fav_prof; | |
string fav_lang; | |
int Java; | |
int C; | |
int Python; | |
int CPP; | |
int C_Hash; | |
int R; | |
cout<<"Enter the Name : "; | |
cin>>name; | |
cout<<"Enter the Age : "; | |
cin>>age; | |
cout<<"Enter the usn : "; | |
cin>>USN; | |
cout<<"Enter the fav prof : "; | |
cin>>fav_prof; | |
cout<<"Enter the fav lang(CPP ,C ,R ,C_Hash, Python, Java) : "; | |
cin>>fav_lang; | |
cout<<"Enter marks in JAVA"; | |
cin>>Java; | |
cout<<"Enter marks in C : "; | |
cin>>C; | |
cout<<"Enter marks in Python : "; | |
cin>>Python; | |
cout<<"Enter marks in CPP : "; | |
cin>>CPP; | |
cout<<"Enter marks in C_Hash : "; | |
cin>>C_Hash; | |
cout<<"Enter marks in R : "; | |
cin>>R; | |
this->Java = Java; | |
this->C = C; | |
this->Python = Python; | |
this->CPP = CPP; | |
this->C_Hash = C_Hash; | |
this->R = R; | |
this->name = name; | |
this->age = age; | |
this->USN = USN; | |
this->fav_prof = fav_prof; | |
this->fav_lang = fav_lang; | |
this->CGPA = calc_cgpa(); | |
} | |
void Student :: show_Student() | |
{ | |
cout<<"Name : "<<name<<endl; | |
cout<<"age : "<<age<<endl; | |
cout<<"usn : "<<USN<<endl; | |
cout<<"cgpa : "<<CGPA<<endl; | |
cout<<"fav prof : "<<fav_prof<<endl; | |
cout<<"fav lang : "<<fav_lang<<endl; | |
} | |
int Student::calc_cgpa() | |
{ | |
return((this->C+this->Java+this->Python+this->CPP+this->C_Hash+this->R)/6); | |
} | |
// getters() for all student members | |
string Student::get_name(){ return name; } | |
int Student::get_age() { return age;} | |
string Student::get_USN(){return USN;} | |
string Student::get_fav_prof(){return fav_prof;} | |
string Student::get_fav_lang(){return fav_lang;} | |
float Student ::get_CGPA(){return CGPA;} | |
int Student::get_Java(){return Java;} | |
int Student::get_C(){return C;} | |
int Student::get_Python(){return Python;} | |
int Student::get_CPP(){return CPP;} | |
int Student::get_C_Hash(){return C_Hash;} | |
int Student::get_R(){return R;} | |
//setters for all student memebers | |
void Student::set_name(string name){ this->name = name;} | |
void Student::set_age(int age){ this->age = age;} | |
void Student::set_USN(string USN){ this->USN = USN;} | |
void Student::set_fav_prof(string fav_prof){ this->fav_prof = fav_prof;} | |
void Student::set_fav_lang(string fav_prof){ this->fav_lang = fav_lang;} | |
void Student ::set_CGPA(float CGPA){ this->CGPA = CGPA;} | |
void Student::set_Java(int x){ this->Java = x;} | |
void Student::set_C(int x){ this->C = x;} | |
void Student::set_Python(int x){ this->Python = x;} | |
void Student::set_CPP(int x){ this->CPP = x;} | |
void Student::set_C_Hash(int x){ this->C_Hash = x;} | |
void Student::set_R(int x){ this->R = x;} | |
Student Student::operator+(Student &B) | |
{ | |
Student t; | |
t.set_CGPA(CGPA + B.CGPA); | |
return t; | |
} | |
/* Start of Professor Class */ | |
class Professor | |
{ | |
private: | |
string name; | |
int age; | |
string prof_id; | |
int salary; | |
string fav_stud; | |
string prog_hand; | |
int rating; | |
public: | |
void read_Professor(); | |
void show_Professor(); | |
/*getters*/ | |
string get_name(); | |
int get_age(); | |
string get_profid(); | |
int get_salary(); | |
string get_fav_stud(); | |
string get_prog_hand(); | |
float get_rating(); | |
// Setters | |
void set_rating(int); | |
// friend void search_stud(Student s, Professor p, string name); | |
}; | |
Professor p[6]; | |
string Professor::get_name() {return name;} | |
int Professor:: get_age(){return age;} | |
string Professor:: get_profid(){return prof_id;} | |
int Professor:: get_salary(){return salary;} | |
string Professor:: get_fav_stud(){return fav_stud;} | |
string Professor:: get_prog_hand(){return prog_hand;} | |
float Professor:: get_rating(){return rating;} | |
void Professor::set_rating(int x){ this->rating = x;} | |
void Professor ::read_Professor() | |
{ | |
string name; | |
int age; | |
string prof_id; | |
int salary; | |
string fav_stud; | |
string prog_hand; | |
cout<<"Enter the Name : "; | |
cin>>name; | |
cout<<"Enter the Age : "; | |
cin>>age; | |
cout<<"Enter the prof id : "; | |
cin>>prof_id; | |
cout<<"Enter the salary : "; | |
cin>>salary; | |
cout<<"Enter the fav stud : "; | |
cin>>fav_stud; | |
cout<<"Enter the prog lang(CPP ,C ,R ,C_Hash, Python, Java) : "; | |
cin>>prog_hand; | |
this->name = name; | |
this-> age = age; | |
this->prof_id = prof_id; | |
this->salary = salary; | |
this->fav_stud =fav_stud; | |
this->prog_hand = prog_hand; | |
} | |
void top_scorer_sub() | |
{ | |
int x; | |
int max=0; | |
int z; | |
// Student s[63]; | |
// Professor p[6]; | |
cout<<"Select the Language"<<endl; | |
cout<<"1. Java\n2. C\n3. Python\n4. C#\n5. CPP\n6. R\n"; | |
cin>>x; | |
switch (x) | |
{ | |
case 1: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_Java() > max) | |
{ | |
max =s[i].get_Java(); | |
z = i; | |
} | |
} | |
break; | |
case 2: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_C() > max) | |
{ | |
max =s[i].get_C(); | |
z = i; | |
} | |
} | |
break; | |
case 3: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_Python() > max) | |
{ | |
max =s[i].get_Python(); | |
z = i; | |
} | |
} | |
break; | |
case 4: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_C_Hash() > max) | |
{ | |
max =s[i].get_C_Hash(); | |
z = i; | |
} | |
} | |
break; | |
case 5: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_CPP()> max) | |
{ | |
max =s[i].get_CPP(); | |
z = i; | |
} | |
} | |
break; | |
case 6: for (int i =0;i<n_stud;i++) | |
{ | |
if (s[i].get_R() > max) | |
{ | |
max =s[i].get_R();; | |
z = i; | |
} | |
} | |
break; | |
default: break; | |
} | |
cout<<"Details of the student scoring maximum marks:\n"; | |
s[z].show_Student(); | |
cout<<"Maximun Mark = "<<max<<endl; | |
} | |
void Professor::show_Professor() | |
{ | |
cout<<"Name : "<<name<<endl; | |
cout<<"Age : "<<age<<endl; | |
cout<<"Professor ID : "<<prof_id<<endl; | |
cout<<"Salary : "<<salary<<endl; | |
cout<<"Program Handled : "<<prog_hand<<endl;; | |
cout<<"Rating : "<<rating<<endl; | |
cout<<endl; | |
} | |
void create_data() | |
{ | |
cout<<"Enter the number of students : "; | |
cin>>n_stud; | |
cout<<"Enter the number of professors : "; | |
cin>>n_prof; | |
cout<<"\nStudents\n"; | |
for (int i =0;i<n_stud;i++) s[i].read_Student(); | |
cout<<"\nProfessors\n"; | |
for (int i =0;i<n_prof;i++) p[i].read_Professor(); | |
} | |
void print_data() | |
{ | |
cout<<"\nStudents Details\n"; | |
for (int i =0;i<n_stud;i++) s[i].show_Student(); | |
cout<<"\nProfessors Details\n"; | |
for (int i =0;i<n_prof;i++) p[i].show_Professor(); | |
} | |
void print_rating(string prof_id) | |
{ | |
int sum = 0, rate; | |
bool flag = false; | |
cout<< "Enter the ratings(1-5) : \n"; | |
for(int i = 0; i < n_stud; ++i) | |
{ | |
cout<< "Student "<< i+1 << "Enter: "; | |
cin>>rate; | |
sum += rate; | |
} | |
sum /= n_stud; | |
string x; | |
for(int i = 0; i< n_prof; ++i) | |
{ | |
string t = p[i].get_profid(); | |
if(t.compare(prof_id) == 0) | |
{ | |
flag = true; | |
p[i].set_rating(sum); | |
} | |
} | |
if(flag) | |
switch(sum) | |
{ | |
case 1: cout<< "Good\n"; break; | |
case 2: cout<< "Better\n"; break; | |
case 3: cout<< "Best\n"; break; | |
case 4: cout<< "Excellent\n"; break; | |
case 5: cout<< "Awesome\n"; break; | |
} | |
else | |
{ | |
cout<< "The professor id was not found!"; | |
} | |
} | |
void get_top_prof() | |
{ | |
int max = p[0].get_rating(), index=0; | |
for(int i = 0; i< n_prof; ++i) | |
if(p[i].get_rating() > max) | |
{ | |
max = p[i].get_rating(); | |
index = i; | |
} | |
cout<< "Top rated professor is:\n"; | |
p[index].show_Professor(); | |
} | |
void top_scorer() | |
{ | |
int max, index; | |
max = s[0].get_CGPA(); | |
for(int i=1; i< n_stud; ++i) | |
{ | |
if(max<s[i].get_CGPA()) | |
{ | |
max = s[i].get_CGPA(); | |
index = i; | |
} | |
} | |
s[index].show_Student(); | |
} | |
void average_students() | |
{ | |
int n; | |
float sum = 0.0; | |
Student t; | |
t.set_CGPA(0.0); | |
cout<< "Enter the number of students: "; | |
cin>>n; | |
for(int i = 0; i < n; ++i) | |
{ | |
t = t + s[i]; | |
} | |
float avg = t.get_CGPA() / n; | |
cout<< "Average of " << n << "Students = " << avg; | |
} | |
void count_fav_lang() | |
{ | |
int java = 0,c = 0,cpp = 0,r = 0,c_hash = 0,python = 0; | |
string str; | |
for (int i=0;i<n_stud;i++) | |
{ | |
str = s[i].get_fav_lang(); | |
transform(str.begin(), str.end(), str.begin(), ::tolower); | |
if(str == "java") java++; | |
else if(str == "python") python++; | |
else if(str == "c_hash") c_hash++; | |
else if(str == "r") r++; | |
else if(str == "cpp") cpp++; | |
else if(str == "c") c++; | |
} | |
cout<<"C : "<<c<<endl; | |
cout<<"C++ : "<<cpp<<endl; | |
cout<<"C Hash : "<<c_hash<<endl; | |
cout<<"R : "<<r<<endl; | |
cout<<"Python : "<<python<<endl; | |
cout<<"Java : "<<java<<endl; | |
} | |
void get_prof_by_stud() | |
{ | |
string stud, prof_name; | |
bool stud_flag = false; | |
bool prof_flag = false; | |
cout<<"Enter the student's name\n"; | |
cin>>stud; | |
for (int i=0;i<n_stud;i++) | |
{ | |
if(s[i].get_name() == stud) | |
{ | |
stud_flag = true; | |
prof_name = s[i].get_fav_prof(); | |
break; | |
} | |
} | |
if(stud_flag) | |
{ | |
for (int i=0;i<n_prof;i++) | |
{ | |
if(p[i].get_name() == prof_name) | |
{ | |
prof_flag = true; | |
p[i].show_Professor(); | |
break; | |
} | |
} | |
if(!prof_flag) | |
cout<<"Invalid Professor Name!!"; | |
} | |
else cout<<"Invalid Student Name!!!"; | |
} | |
int main() | |
{ | |
string st; | |
int choice; | |
while (1) | |
{ | |
cout<<"\n1. Add Data\n2. Print Details\n3. Top scorer in particular language\n4. Rate Professor\n5. Find top rated Professor\n6. Top Scorer\n7. Average CGPA of students\n8. Count fav language\n9. Prof details from student name\n10. Exit\n"; | |
cout<<"Enter choice : "; | |
cin>>choice; | |
switch (choice) | |
{ | |
case 1: create_data(); | |
break; | |
case 2: print_data(); | |
break; | |
case 3: top_scorer_sub(); | |
break; | |
case 4: | |
cout<<"Enter the professor's ID"; | |
cin>>st; | |
print_rating(st); | |
break; | |
case 5: get_top_prof(); | |
break; | |
case 6: top_scorer(); | |
break; | |
case 7: average_students(); | |
break; | |
case 8: count_fav_lang(); | |
break; | |
case 9: get_prof_by_stud(); | |
break; | |
case 10: exit(0); | |
default: cout<<"Invalid option"; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment