Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class TwoNumbers Please see attached file. Complete the whole program by writing

ID: 3535542 • Letter: C

Question

Class TwoNumbers
Please see attached file.
Complete the whole program by writing your own TwoNumbers Class.





// This program demonstrates C++ class concept

#include <iostream>

#include <cstdlib>

using namespace std;


class TwoNumbers

{

private:

int n1, n2;

double avg, sum, product;

.

.

.

};




int main()

{

// Create a TwoNumbers objects.

TwoNumbers N1(39500, 673), N2;


N1.average(); // calculate average, then assign to private variable avg

N1.add(); // calculate total, then assign to private variable sum

N1.multiply(); // calculate multiplication, then assign to private variable product

N1.print(); // print object info


N2.setNumber1(50);

N2.setNumber2(5);

N2.average();

N2.add();

N2.multiply();

N2.print(); // print object info


// create object N3 and assign the two numbers by using the formula given below

TwoNumbers N3(N1, N2); // (N1.num1 + N2.num1) (N1.num2 + N2.num2)

N3.average();

N3.add();

N3.multiply();

N3.print(); // print object info


system("pause");

return 0;

}

Explanation / Answer

Here is what your class would be:


class TwoNumbers

{

  private:

int n1, n2;

double avg, sum, product;

TwoNumbers(int a,int b)

{

n1=a;

n2=b;

}

void avg()

{

avg=(n1+n2)/2;

}

void sum()

{

sum=n1+n2;

}

void print()

{

cout<<n1<<" "<<n2<<endl;

}

void SetNumber1(int a)

{

n1=a;

}

void SetNumber2(int a)

{

n2=a;

}

};