Files
ooplab/lab2/6.cpp
2022-12-26 16:30:38 +05:30

72 lines
1.2 KiB
C++

#include <iostream>
using namespace std;
const uint NSUBS = 5;
const uint NSTUDENTS = 5;
class Student {
private:
char name[30];
char branch[20];
uint enrollment;
uint age;
char gender;
uint marks[NSUBS];
double percentage;
public:
void input();
char *getName();
double getPercentage();
};
void Student::input() {
uint s = 0, i;
cout << "Name: ";
cin >> this->name;
cout << "Branch: ";
cin >> this->branch;
cout << "Enter Enrollment number: ";
cin >> this->enrollment;
cout << "Age: ";
cin >> this->age;
cout << "Gender (m/f): ";
cin >> this->gender;
cout << "Enter Marks for" << endl;
for (i = 0; i < NSUBS; i++) {
cout << "Subject " << i + 1 << ": ";
cin >> this->marks[i];
if (marks[i] > 100)
exit(1);
s += this->marks[i];
}
this->percentage = (double)s / NSUBS;
}
inline char *Student::getName() { return this->name; }
inline double Student::getPercentage() { return this->percentage; }
int main() {
int i;
Student a[NSTUDENTS];
for (i = 0; i < NSTUDENTS; i++)
a[i].input();
cout << "\nStudents with percentage greater than 70:\n";
for (i = 0; i < NSTUDENTS; i++)
if (a[i].getPercentage() > 70)
cout << a[i].getName() << endl;
return 0;
}