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
Can Word Processing (WP) programs be used for DTP? Explain your answer
siniylev [52]

Word Processing Programs cannot be used for DTP

Explanation:

DTP software cannot be replaced with Word Processing Programs.  DTP software is used for creating publishing document like post card, business card, calendars, and books where as the word processing software is used for creating and editing predominantly text document and once can edit text, copy, paste , delete and format text. Word processor relies heavily on editing of the contents rather than graphics or page layout where as DTP software is used to create image heavy newsletters, magazines, adverts, and brochures where layout is important.

4 0
3 years ago
Which file type is the best choice if the image will be made into a billboard?
matrenka [14]

Answer:

BMP

Explanation:

They are high resolution and are suitable for billboards.

6 0
1 year ago
What is the difference between HTML and CSS? * 1. CSS is a markup language unlike HTML 2. HTML is a backend technology and CSS i
grin007 [14]

Answer: 3. HTML focuses on a web page's structure and CSS focuses on its presentation.

Explanation: HTML is designed to allow you to add the content and format it correctly. However, CSS's job is to allow for stylizing.

4 0
3 years ago
Full form of http.<br>wrong answer will be reported ​
vodomira [7]

Answer:

So it is Hyper Text Transfer Protocol.

Hope it helps

6 0
3 years ago
Read 2 more answers
What will be the output of “AAAAMMMMMHHHVV” using a file compression technique?
jeka94

Answer:

it would be amhv i think i hope it answered u'er question

Explanation:

8 0
3 years ago
Other questions:
  • Will upvote all answers
    7·1 answer
  • Writers should avoid jargon because jargon ______. a. Takes too long to use b. Limits what ideas can be explored c. Conveys too
    12·1 answer
  • A hacker uses a valid IP address of an internal host, and then from an external system, the hacker attempts to establish a commu
    11·1 answer
  • sqrt is being defined as a variable name, how do I get its math function to... well... function? (Python)
    11·1 answer
  • Fact about energy that will make a knex car move
    7·2 answers
  • “identify the skill in the following scenario” :
    6·2 answers
  • The introduction of new information technology has a: A. dampening effect on the discourse of business ethics. B. waterfall effe
    14·1 answer
  • What is a file type and why is it important? Give at least three examples of file
    7·1 answer
  • Explain any 10uses of computer that are specific to your field of study giving appropriate examples​
    13·1 answer
  • I need to calculate the % of Grand Total on Microsoft Excel, but can't for the life of me remember how to do that. Help would be
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!