Declare a class named MyNumbers. It includes the following members:
1. Data Member: num that is an
integer array with size 20.
2. Method: getSum which will find the sum
of all numbers in data member.
3. Method: getAvg which will find the average of all number
in data member.
4. Method: sort which sort the data in ascending order
5. Method: print which print the data
member.
6. Constructor
In main function, you should read the data below from a data file and
create an object to have the initial value as what you read:
13 14 2
6 7 90 56 23 78 82 120 1
9 3 44 62 98 8 6 0
My suggestion to you is followed:
You create a project included three files:
MyNumbers.h
declare class here
MyNumbers.cpp implement methods and
constructor here
Application.cpp write
main function here to create an object and call methods
Example: The following three files are included in one project.
|
Boy.h file |
Boy.cpp file |
class Boy
{
private:
float Height, Weight;
public:
//Constructor
Boy(float Hei=0, float Wei=0);
void Grow(float H1);
void Print(void);
};
|
#include"Boy.h"
#include<iostream>
using namespace std;
Boy::Boy(float Hei, float Wei)
{
Height = Hei;
Weight = Wei;
}
void Boy::Grow(float H1)
{
Height = Height + H1;
}
void Boy::Print(void)
{
cout<<"The height is "<<Height<<endl;
cout<<"The weight is "<<Weight<<endl<<endl;
}
|
|
Application.cpp file |
Output |
#include"Boy.h"
#include <iostream>
using namespace std;
void main()
{
Boy Austin(70, 120);
Austin.Print();
Austin.Grow(12);
Austin.Print();
Boy Terry;
Terry.Print();
Boy Kenny(67);
Kenny.Print();
}
|
|