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
The readline method reads text until an end of line symbol is encountered, how is an end of line character represented
zhannawk [14.2K]

Answer:

\n

Explanation:

readline() method is used to read one line from a file. It returns that line from the file.    

This line from the file is returned as a string. This string contains a \n at the end which is called a new line character.

So the readline method reads text until an end of line symbol is encountered, and this end of line character is represented by \n.

For example if the file "abc.txt" contains the lines:

Welcome to abc file.

This file is for demonstrating how read line works.

Consider the following code:

f = open("abc.txt", "r")  #opens the file in read mode

print(f.readline()) # read one line from file and displays it

The output is:

Welcome to abc file.    

The readline() method reads one line and the print method displays that line.                        

3 0
3 years ago
What type of cable is used to connect a workstation serial port to a cisco router console port?
butalik [34]

a <span>Ethernet-<span>Cable is a how to put it together</span></span>

<span><span /></span>

6 0
3 years ago
The commands available from a menu do not change. True or false
jeka94

i believe this will be false


3 0
3 years ago
Read 2 more answers
Smartphones use ________ technology, allowing users to perform several functions with one device. group of answer choices embedd
12345 [234]

Smartphones use <u>convergence or integration</u> technology, allowing users to perform several functions with one device.

<h3>What are smartphones?</h3>

Smartphones can be defined as hybrid versions of mobile devices that are designed and developed to have more features, so as to enable them run different software applications, functions and perform tasks with the aid of software applications such as web browsers, multimedia player, etc.

<h3>Types of smartphones.</h3>

In Computer technology, there are three popular types of mobile devices and these include the following:

  • Handheld computers
  • Personal digital assistants (PDAs)
  • Smartphones.

In Computer technology, smartphones are designed and developed to use <u>convergence or integration</u> technology by combining previously unrelated technologies together, in order to allow end users perform several functions with one device.

Read more on smart phones here: brainly.com/question/15867542

#SPJ1

8 0
2 years ago
An automated search feature used by search engines to find that match your search terms is called a spider or
9966 [12]

Answer

Crawler

Explanation

This is a program that go to various website to read their pages and content provided in order to form entries for a search engine index.All search engines have this program called spider or a bot. It acts as an automated script that browses through the internet to scan the web pages and find words contained in the pages and where the words are used.


5 0
3 years ago
Read 2 more answers
Other questions:
  • Abigail is interested in connecting her tablet that usually connects to a wireless network, to her personal computer that usuall
    11·2 answers
  • What does "CPU" stand for?
    5·2 answers
  • What are the two different frequencies WiFi operates on?
    9·2 answers
  • Troubleshooting a printer that does not work includes a. connecting the printer to your computer b. checking to see if there is
    13·1 answer
  • In the beginning of a presentation, it is important to:
    9·1 answer
  • Which of the following sets of acronyms is concerned with encoding data for secure transmission?
    11·1 answer
  • Select the correct answer.
    5·2 answers
  • Describe the difference between a myth and a fable.
    12·1 answer
  • List out any four hardware and software components required for multimedia​
    10·1 answer
  • Who can give me answer for this kinda urgent pls
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!