Using c++ Using c++ 5. Write a complete program tor the folowing problerm, The p
ID: 3733430 • Letter: U
Question
Using c++ Using c++ 5. Write a complete program tor the folowing problerm, The progreminars and the main )1 t use the class declaration to produce the 1/0. You are supposed to write all members create the given I/O class FIVE ( private: int x[7]: Sample / Enter 7 integer data: 22 77 33 99 11 10 23 All data: 22 77 33 99 11 10 23 Maximum 99 Minimum 10 Total 275 public: void READ) //read data in arrayx void Display) //display arrayx void FindMaxMin (int& mx, int& mn) //return the max and min data in arrayx int FindTotal() //return the sum of data in array x 690Explanation / Answer
The C++ code is here, hope it helps (I have added comments) :
#include<iostream>
using namespace std;
class FIVE
{
private: int x[7];
public:
void READ() //reading input for the array
{
cout<<"Enter 7 integer data: ";
for(int i=0;i<7;i++)
cin >> x[i];
}
void Display() //displaying the array output
{
cout<<"All data: ";
for(int i=0;i<7;i++)
cout << x[i] << " ";
}
void FindMaxMin(int &mx, int &mn) // returning max and min of the array
{
mx=mn=x[0];
for(int i=1;i<7;i++){
if(x[i]>mx)
mx=x[i];
if(x[i]<mn)
mn=x[i];
}
}
int FindTotal() //returns sum of the array
{
int t=0;
for(int i=0;i<7;i++)
t=t+x[i];
return t;
}
};
int main(){
int total,mx,mn;
FIVE ob1;
ob1.READ();
ob1.Display();
ob1.FindMaxMin(mx,mn);
total=(ob1.FindTotal());
cout<<" Maximum: "<< mx;
cout<<" Minimum: "<< mn;
cout<< " Total: " << total ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.