0% found this document useful (0 votes)
45 views2 pages

Student String: Using Namespace Struct

The document defines a student struct with name, year of birth, 3 test scores, grade, and age fields. It then declares an array of 100 student structs. Functions are defined to read student data from input, calculate student ages by subtracting year of birth from the current year, calculate the average grade for each student, find the student with the highest average, find the oldest student, and output the names of students with averages over 95.

Uploaded by

Tamer Al Rajabi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Student String: Using Namespace Struct

The document defines a student struct with name, year of birth, 3 test scores, grade, and age fields. It then declares an array of 100 student structs. Functions are defined to read student data from input, calculate student ages by subtracting year of birth from the current year, calculate the average grade for each student, find the student with the highest average, find the oldest student, and output the names of students with averages over 95.

Uploaded by

Tamer Al Rajabi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <string>
using namespace std;

struct student
{
string firstname;
int yearofbairth;
double score1, score2, score3;
double grade;
int age;
};

student st[100];
int main() {
int size;
system("pause");
return 0;
}

void Read(int size) {


for (int i = 0; i < size; i++)
{
cout << "Student Number : " << i + 1 << endl;
cout << "Enter the name : " << endl;
cin >> st[i].firstname;
cout << "Enter the year of birth : " << endl;
cin >> st[i].yearofbairth;
cout << "Enter the score one : " << endl;
cin >> st[i].score1;
cout << "Enter the score two : " << endl;
cin >> st[i].score2;
cout << "Enter the score three : " << endl;
cin >> st[i].score3;
}
}

void FindAge(int size) {


for (int i = 0; i < size; i++)
{
st[i].age = 2017 - st[i].yearofbairth;
}
}

void Findgrade(int size) {


for (int i = 0; i < size; i++)
{
st[i].grade = ((st[i].score1 + st[i].score2 + st[i].score3) / 3);
}
}

void Bestavarge(int size) {


double max = st[0].grade;
int x = 0;
for (int i = 0; i < size; i++)
{
if (st[i].grade>=max)
{
max = st[i].grade;
x = i;
}
}
cout << "The Best Avarge : " << st[x].firstname << endl;
}

void Oldest(int size) {


int max = st[0].age;
int x = 0;
for (int i = 0; i < size; i++)
{
if (st[i].age>max)
{
max =st[i].age;
x = i;
}
}
cout << "The Oldest Student : " << st[x].firstname << endl;
}

void Honors(int size)


{
cout << "The Student have average greater than 95 " << endl;
for (int i = 0; i < size; i++)
{

if (st[i].grade>95)
{
cout << st[i].firstname << endl;
}
}
}

You might also like