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
2 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]2 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
Which of the following commands can be used to display socket information out to the terminal screen
Slav-nsk [51]
Linus ss

Explanation:

The ss (socket statistics) command provides a lot of information by displaying details on socket activity. One way to get started, although this may be a bit overwhelming, is to use the ss -h (help) command to get a listing of the command's numerous options. Another is to try some of the more useful commands and get an idea what each of them can tell you.

One very useful command is the ss -s command. This command will show you some overall stats by transport type. In this output, we see stats for RAW, UDP, TCP, INET and FRAG sockets.
6 0
1 year ago
What is web browser <br>​
xeze [42]
An application used to access and view websites
7 0
3 years ago
Read 2 more answers
What are the primary functions of motor oil? a. Reduce friction and prevent wear b. Keep engine surfaces clean c. Remove heat to
ryzh [129]

The answer is E: all of the above.

7 0
3 years ago
Which of the following scan only works if operating system’s TCP/IP implementation is based on RFC 793?
Shkiper50 [21]

Answer:NULL Scan

Explanation:RFC 793(Request for comments) is a type of RFC command labeled with the number 793 which can operate with the TCP protocol.They are sort of document form which is from IETF( Internet Engineering Task Force ).

The null scan is scanning protocol used by legal as well as illegal hackers for working in the transfer control protocol architecture. It is used for the identification of the the ports and holes in TCP servers.they can also have the negative impact if used by the illegal hackers.

5 0
2 years ago
9) If you are working on the part of 5-15 minutes, time-stamping (every 30 seconds) should start at: a) [00:05:00] b) [00:00:00]
loris [4]

Answer:

a) [00:05:00]

Explanation:

Timestamps are markers in a transcript which are used to represent when an event took place. Timestamps are in the format [HH:MM:SS] where HH is used to represent hour, MM to represent the minute and SS to represent the seconds. They are different types of timestamping such as:

i) Periodic time stamps: Occurs at a consistent frequency

ii) Paragraph time stamping: At the beginning of paragraphs

iii) Sentence time stamp: at the beginning of sentence

iv) Speaker time stamp: at change of speaker.

Since a part of 5-15 minutes with time-stamping (every 30 seconds), The time stamping should start at 5 minute [00:05:00] and end at [00:15:00]. This is a periodic time stamp since it occurs every 30 seconds, this means the next time stamp would be [00:05:30] and this continues until 15 minute [00:15:00]

3 0
3 years ago
Other questions:
  • you want to discard your old computer ,want to securely erase that data from your hard drive. what can you use to do this and wh
    12·1 answer
  • Find the 65th percentile from the data. The data consist of class interval from 0-10, 10-20, 20-30, 30-40, 40-50, 50-60 and freq
    8·1 answer
  • Where do you access the status report of an assigned task that is open?
    12·2 answers
  • list six external parts or peripherals of a computer system and identify which are output and which are input devices
    8·1 answer
  • Physical activity such as sports or even a brisk walk can help reduce
    7·2 answers
  • An online service allows users to integrate their phonebook with their social media profiles and stores it on the cloud. The pho
    12·1 answer
  • Complete the body of the decrement static method using only the NaturalNumberKernel methods (multiplyBy10, divideBy10, and isZer
    10·1 answer
  • Rule number one for handling an emergency is to _____. A. buy a new vehicle B. call law enforcement C. remain calm D. restart th
    6·2 answers
  • WILL GIVE BRAINLIEST!!!!!!!
    10·2 answers
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!