Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://github.com/triffon/oop-2019-20/tree/master/labs/5/Practice_01
- #include<iostream>
- using namespace std;
- const unsigned short gradeCount = 5;
- struct Student{
- unsigned long long EGN;
- char firstName[30];
- char lastName[30];
- unsigned facNum;
- double grades[5];
- void input() {
- cout<<"EGN: ";
- cin>>EGN;
- cout<<"ime: ";
- cin.get();
- cin.getline(firstName,29);
- cout<<"famil: ";
- cin.getline(lastName,29);
- cout<<"FN: ";
- cin>>facNum;
- cout<<"ocenki ("<<gradeCount<<" na broi): \n";
- for(int i=0; i<gradeCount; i++) {
- cin>>grades[i];
- }
- }
- void print() {
- cout<<firstName<<" "<<lastName<<" "<<EGN<<" "<<facNum<<" ";
- for(int i=0;i<gradeCount;i++) {
- cout<<grades[i];
- }
- }
- double avgGrade() {
- double sum=0;
- for(int i=0;i<gradeCount;i++) {
- sum+=grades[i];
- }
- return sum/gradeCount;
- }
- };
- void addStudent(Student studs[], unsigned short &countS) {
- cout<<endl<<"Info about student " << countS+1<< ": \n";
- studs[countS].input();
- countS++;
- }
- void printAllStudents(Student studs[], unsigned short countS) {
- cout<<endl;
- if(countS==0) {
- cout<<"nqma studenti v masiva";
- return;
- }
- for(unsigned short i=0; i<countS; i++) {
- studs[i].print();
- cout<<endl;
- }
- }
- void printMarch(Student studs[], unsigned short countS) {
- cout<<endl;
- if(countS==0) {
- cout<<"nqma studenti v masiva";
- return;
- }
- for(unsigned short i=0; i<countS; i++) {
- if(((studs[i].EGN/1000000)%10)==3) {
- cout<<studs[i].firstName<<" "<<studs[i].lastName<<" "<<studs[i].avgGrade();
- }
- cout<<endl;
- }
- }
- void avgGrades(Student studs[], unsigned short countS) {
- cout<<endl;
- if(countS==0) {
- cout<<"nqma studenti v masiva";
- return;
- }
- for(unsigned short i=0; i<countS; i++) {
- cout<<studs[i].avgGrade()<<endl;
- }
- }
- void maxAvgGrade(Student studs[], unsigned short countS) {
- cout<<endl;
- if(countS==0) {
- cout<<"nqma studenti v masiva";
- return;
- }
- double maxG=0;
- for(unsigned short i=0; i<countS; i++) {
- double currG = studs[i].avgGrade();
- if(maxG<currG) maxG=currG;
- }
- cout<<maxG;
- }
- int main() {
- const int MAX_STUD = 10;
- Student students[MAX_STUD];
- short unsigned studCount = 0;
- int menuind=1;
- while(menuind) {
- cout<<"\n\n0 - exit \n1 - add new student \n2 - output march bois \n3 - output highest average grade \n";
- cin>>menuind;
- switch(menuind) {
- case 1:
- addStudent(students,studCount);
- break;
- case 2:
- printMarch(students,studCount);
- break;
- case 3:
- maxAvgGrade(students,studCount);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement