Question

using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

using c/c++

Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that

  1. Receives two integer numbers as parameter and returns the average
  2. Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above
  1. Define a class named Student with following members:
    1. private data: 2 grades and a GPA (average).
    2. public constructor to initialize the members
    3. a public function named SetGrades that has two parameters to be used to set the grades, and returns true if numbers are both acceptable (between 0 and 100) and returns false with no change in grades if numbers are not acceptable.
    4. a public function named GetGPA that calculates and returns the GPA (using the Average function).
  2. Use the Student class in main() so that it
    1. creates a Student object
    2. sets the numbers user has entered as grades for student
    3. gets the average from the Student object and prints it
    4. stays in a loop and repeats
  3. Define a child class named Student2 based on Student that
    1. overrides Student::SetGrades and adds a call to Average to set the GPA when the grades are changed
    2. overrides the Student::GetGPA so no call is made to Average, and only the current GPA is returned
  4. Modify the Average function so it receives an array of int numbers and an int size
    1. Write the code for Average so that it calculates the average of the array
    2. Modify the Student and Student2 classes to have work with the new Average function (hint: use an array for grades instead of two separate variables)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a)

#include <iostream>
using namespace std;
int i=0;
float avg;
int average(int x, int y);
int main()

{
while(i<=1)

{
cout<<i;
int a,b;
cout << "Enter a integers : " << endl;
cin>>a;
if(i==0)
{
b=a;

}
if(i==1)
{

float ret = average(a,b);

cout << "The average of " << a << " and "<<b<< " is " << ret<< "." << endl;
}
i++;

}

}
int average(int x,int y)
{
int sum;
sum=x+y;
avg=sum/2;

return avg;

}

Add a comment
Know the answer?
Add Answer to:
using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • 3. Write a program following the requirements below: (20 marks) (a) Write a function named average()...

    3. Write a program following the requirements below: (20 marks) (a) Write a function named average() that calculates and returns the average value of 3 single-precision floating-point numbers. (b) Include the function in a working program and test the functionality of the function average( ). Make sure your function is called from main() and correctly returns a value to main().

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • a. Write a function named findmax() that finds and displays the maximum values in a two...

    a. Write a function named findmax() that finds and displays the maximum values in a two dimensional array of integers. The array should be declared as a 10 row by 20 column array of integers in main() and populated with random numbers between 0 and 100. b. Modify the function written above so that it also displays the row and column numbers of the element with the maximum value. I have this so far, and but it's only finding the...

  • 2. Write a program named lab3 2.app that contains a class named Student to store student...

    2. Write a program named lab3 2.app that contains a class named Student to store student information Information that will be relevant to store is first name, last name, id number, GPA, and major (1) Define a member function named set0, which allows you to set all member variables. This function has an empty parameter list, and its return type is void. So, within the function you'll prompt for information. Note: For entering major, if you need a space, use...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); //...

    // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT