1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jeka94
3 years ago
15

Given ProblemSolution class. Use a pointer to object of "ProblemSolution" class to invoke the "CalculateSum" and "Print" methods

of "ProblemSolution".
Write a function:
void Solution(int N1, int N2)

that accepts two integers N1 and N2. The function should instantiate "ProblemSolution" object with N1 and N2 values and call "CalculateSum" and "Print" method by creating a pointer to the object of "ProblemSolution".

Input
12 5

Output
17
Assume that,

N1, N2 and sum are integers within the range [-1,000,000,000 to 1,000,000,000].
Given Code to work with:

#include
#include
#include
using namespace std;

class ProblemSolution{
int N1,N2,result;
public:
ProblemSolution(int N1, int N2){
Computers and Technology
1 answer:
faltersainse [42]3 years ago
3 0

Answer:

#include <iostream>

using namespace std;

class  ProblemSolution {

private:

int num1, num2;

public:

ProblemSolution(int n1, int n2) {

 num1 = n1;

 num2 = n2;

}

int calculateSum() {

 int sum = 0;

 sum = num1 + num2;

 return sum;

}

void printSum() {

 // calculateSum will return sum value that will be printed here

 cout <<"Sum = "<< calculateSum();

}

~ProblemSolution() {

 cout << "\nDestructor is called " << endl;

};

};

int main() {

int a, b;

cout << "Enter a: ";

cin >> a;

cout << "Enter b: ";

cin >> b;

// Initiallizing object pointer of type ProblemSolution

ProblemSolution *objPtr = new ProblemSolution(a,b);

// printing Sum

objPtr->printSum();

// delete objPtr to relaease heap memory :important

delete objPtr;

return 0;

}

Explanation:

we will initialize  a pointer "objPtr" and initallize the constructor by passing 2 values a and b followed by the keyword  "new". the keyword "new" allocates memory in the heap. we can access class member functions using arrow "->". it is important to delete objPtr at the end of the program so that the heap memory can be freed to avoid memory leakage problems.  

You might be interested in
Suppose that Alice wants to send Bob a 50 kilobyte message over a 1 Gbps link. The total time required to transmit the message (
svlad2 [7]

Answer:

170 Mbps

Explanation:

Time taken to put data on to the link T1 = 50kB / 1 Gbps = 0.0004096

Time taken for transmission T2 = 2 milliseconds = 2 * 10-3

--> throughput = ( 1 / (1+T2/T1) ) * bandwidth of link

= ( 1 / (1 + 4.8828125) ) * 1 Gbps

= 0.16998672 * 1 Gbps

= 169.98672 Mbps

= 170 Mbps.

8 0
4 years ago
What is the name of the organization responsible for assigning public ip​ addresses?
Veseljchak [2.6K]
Comcast,at&t,and Verizon
8 0
3 years ago
I need help with this
Mila [183]

Either Styles or Formula


5 0
3 years ago
Read 2 more answers
A. what company or individual is responsible for developing the windows operating system?
Gwar [14]
Microsoft is responsible for developing the windows operating system. 
5 0
4 years ago
(3)(6 Points) During a sale at a store, a 10% discount is applied to purchases over $10.00. Write a program that asks for the am
Galina-37 [17]
I only need point sort
7 0
3 years ago
Other questions:
  • 1. Which of the following might be a problem taken on by environment engineers?
    8·1 answer
  • Gunther is filling in his own input mask. He wants to format the Social Security numbers of his clients. The field must contain
    5·1 answer
  • Two circuits are created using two identical light bulbs. In the circuit A, the bulbs are hooked up in series. In circuit B, the
    7·2 answers
  • What is a detailed and thorough review of the deployed security infrastructure compared with the organization’s security policy
    5·1 answer
  • (8.03)
    5·1 answer
  • One major challenge in developing an international information system is to find​ a(n) ________ when there is so much cultural a
    11·1 answer
  • What are the disadvantages of a Cessna 172?
    6·1 answer
  • As the first step, load the dataset from airline-safety.csv by defining the load_data function below. Have this function return
    9·1 answer
  • Any BTS army here
    6·2 answers
  • Carmen has met new people online that she enjoys talking to. One of these people has asked her to meet at the park in person and
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!