Answer to Question #273871 in C++ for SUNIL

Question #273871

Design a class Student. Include data members rollno, name, city and age. Write member functions:

i) To accept information of ‘n’ students

ii) To display information of ‘n’ students

iii) To search details of a student using rollno

(use array of objects)

Iv. Calculate Average age.


1
Expert's answer
2021-12-04T20:56:14-0500
#include <iostream>

using namespace std;

class Student 
{
  string rollno;
  string name;
  string city;
  int age;
};

void read_info(Student *students, int n) {
 for (int i = 0; i < n; i++) {
   cin >> students[i].rollno
       >> students[i].name
       >> students[i].city
       >> students[i].age >> endl;
 }
}

void display_info(Student *students, int n) {
 for (int i = 0; i < n; i++) {
  cout << "Rollno: " << students[i].rollno << "\n"
       << "Name: " << students[i].name << "\n"
       << "City: " << students[i].city << "\n"
       << "Age: " << students[i].age < "\n";
 }
}

Student *find(Student *students, int n, string rollno) {
 int idx = -1;
 for (int i  = 0; i < n; i++) {
  if (students[i].rollno == rollno) idx = i;
 }
 if (idx != -1) return &students[i].
 else return nullptr;
}

double avg_age(Student *students, int i) {
 double total = 0;
 for (int i = 0; i < n; i++)
  total += students[i].age;
 return total / n;
}

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