Write an interactive C++ program that prompts the user for ten (10) real numbers and calculate the sum, average, and prints the result. Hint: you may use an array to store the data.

Program requirements:
- The program must contain a class in which all the required private and public identifiers and the following functions must be defined.
- The program must contain three or more functions using parameters. These functions should read the data, calculate the sum, find the average, and print the results.


I'm really not that good, this is what I have so far! But I know this is not what my teacher wants, I have no knowledge yet of private...


#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int score1 = 0;
int score2 = 0;
int score3 = 0;

int main()
{
cout << "Enter the first score: ";
cin >> score1;
cout << "\nEnter the second score: ";
cin >> score2;
cout << "\nEnter the third score: ";
cin >> score3;
cout << "\nThe average of the 3 scores is " << (score1 + score2 + score3) / 3 << endl;
system("PAUSE");
return 0;

Here is a possible answer without using a Class.. you can use the algorithm(s) below when you put together your class in your program.

#include <iostream>
using namespace std ;

int main()
{
     int score[i], 
         total = 0 ;
     
     for(int i=0; i<10; i++)
     {
          cout << "\nEnter an integer: " ;  
          cin >> score[i] ;        
          total += score[i] ;
     }

     cout << "\n\n\tThe sum is: " << total ;

     cout << "\n\n\tThe average is: " << total / 10 ;


return 0 ; 
}

try the following code:

#include <iostream.h>
#include <conio.h>

class real
{
	double n[10],s;
	int i;
	double avg;

public:
	real()
	{
		s=0;
	}

	void read()
	{
	
		for (i=0;i<10;i++)
		{
		cout<<"Enter a number	:";
		cin>>n[i];
		}
	}

	void print()
	{
		cout<<"The numbers entered are		:"<<endl;
		for (i=0;i<10;i++)
		{
		cout<<n[i]<<endl;
		}
	}

	void sum()
	{
	
		for (i=0;i<10;i++)
		s=s+n[i];
	}

	void average()
	{
		avg=s/10;
	}

	void printres()
	{
		cout<<"Sum		="<<s<<endl;
		cout<<"Average	="<<avg<<endl;
	}
};

void main()
{
	real r;
	r.read();
	r.print();
	r.sum();
	r.average();
	r.printres();
}
Member Avatar for iamthwee

It might also be helpful to explain what they do when you decide to do someone else's homework?

ok...that's true...i'll do that...thank u..

class is a way by which you can define a user-defined data type in c++.
private members are visible only inside a class; u cant access from outside.
public members can be accessed outside the class using an object.
object is a variable of a user-defined data type.
an array is a data structure that can store more than one data of the same data type in a common name.
the member function read() - reads 10 numbers in an array.
the member function print()- prints the 10 numbers
sum() finds the sum of all numbers
average() finds the average of all numbers
printres() prints the sum and the average

Member Avatar for iamthwee

It might also be helpful to explain what they do when you decide to do someone else's homework?

Irony my little friend, what I meant to say was you shouldn't be doing someone else's homework in the first place.

If you spent the same amount of time doing your own homework as you do with other people's you shouldn't need to ask how to read in hexadecimal numbers in c++.

Tee he he

God bless.

If you spent the same amount of time doing your own homework as you do with other people's you wouldn't be using void main()

I fixed your post ;)

Member Avatar for iamthwee

I fixed your post ;)

Or <iostream.h>

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.