Question 2
Figure below shows that Student is a structure consisting of four different objects. The figure below illustrates how a struct is declared, how its constituent data members are accessed, and how it can be passed as a parameter to a function. You need to calculate the grade point average from the given pointer1 and pointer2. We have the declaration:
Student s;
struct number
{
string firstName;
string 1astName;
int studentNum;
int pointer1;
int pointer2;
};
Write a program that produce an output that will call struct Student for last name, first name, pointer1 and pointer 2 for a student named Mary.
#include<iostream>
#include<string>
using namespace std;
struct Student
{
string firstName;
string lastName;
int studentNum;
int pointer1;
int pointer2;
void print();
};
void Student::print()
{
cout << "Last name " << lastName << " first name " << firstName << " pointer1 " << pointer1 << " pointer2 " << pointer2 << endl;
}
double aver(Student s);
int main()
{
Student Mary;
Mary.firstName = "Mary";
Mary.lastName = "Green";
Mary.pointer1 = 5;
Mary.pointer2 = 4;
Mary.print();
cout << aver(Mary) << endl;
system("pause");
return 0;
}
double aver(Student s)
{
return (double)(s.pointer1 + s.pointer2) / 2.0;
}