Answer to Question #175087 in C++ for osama

Question #175087

Write a program in C++ which stores and displays the details of 3 students in arrays. Your program should:  Take the following inputs from the user: Name, department, year of enrolment, discipline, age, gender, gpa. Choose appropriate data types for the arrays to store each type of input information.  Once the details of the student have been entered in the different arrays, display a summary of the details for the student.  In the next step, calculate the average gpa of the three students and display it.  In the final step, swap the discipline and gpa of Student1 and Student2.  Display the final updated summary details for each student.


1
Expert's answer
2021-03-24T12:46:13-0400
#include <iostream>

#include <string>

using std::string;

using std::cout;

using std::cin;

using std::endl;




struct Student

{

  string name;

  string departament;

  int year{ 0 };

  string discipline;

  int age{ 0 };

  string gender;

  int gpa{ 0 };

};




void showInfo(Student student) 

{

  cout << "Name :" << student.name << "\n";

  cout << "Departament :" << student.departament << "\n";

  cout << "Year of enrolment :" << student.year << "\n";

  cout << "Discipline:" << student.discipline << "\n";

  cout << "Age :" << student.age << "\n";

  cout << "Gender :" << student.gender << "\n";

  cout << "Gpa :" << student.gpa << "\n";

}

Student setData(Student student)

{

  cout << "Enter name :" <<"\n";

  cin >> student.name;

  cout << "Enter departament :" << "\n";

  cin >> student.departament;

  cout << "Enter year of enrolment :" << "\n";

  cin >> student.year;

  cout << "Enter discipline:" << "\n";

  cin >> student.discipline;

  cout << "Enter age :" << "\n";

  cin >> student.age;

  cout << "Enter gender :" << "\n";

  cin >> student.gender;

  cout << "Enter gpa :" << "\n";

  cin >> student.gpa;

  return student;

}

int main()

{  

  const int n = 3;

  Student s[n];

  for (int i =0; i <3;i++)

  {

    cout << "Enter dataset for " << i + 1 << " student" << endl;

    s[i] = setData(s[i]);

    //output of brief information about the sudent

    cout << "Name" << s[i].name << "Discipline" << s[i].discipline << "Gpa" << s[i].gpa << endl;

  }

  float avg_gpa = (s[0].gpa + s[1].gpa + s[2].gpa) / 3;

  cout << "Mean gpa - " << avg_gpa << endl;

  string swap_dis = s[0].discipline;

  int swap_gpa = s[0].gpa;

  s[0].discipline = s[1].discipline;

  s[0].gpa = s[1].gpa;

  s[1].discipline = swap_dis;

  s[1].gpa = swap_gpa;




  for (int i = 0; i < 3; i++) 

  {

    cout << "Info of " << i + 1 << " student" << endl;

    showInfo(s[i]);

  }

  return 0;

 }


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS