Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with A few C++ questions that are listed below.the first one is a simple code question and the others are yes/no questions.

I need help with A few C++ questions that are listed below.the first one is a simple code question and the others are yes/no questions. Thank you

1. Write a simple program which prompts the user for a positive integer n and outputs the sum of the first n positive integers. This particular problem can be solved with an expression, with iteration, and with recursion. Implement each solution. For those who cant remember, the sum of the first n positive integers is n* (n+1) / 2. (please include the solutions using the three ways listed above).

2. Consider the following two class implementations. Is the integer array part of the member data?

class exa

{

private:

int value;

public: exa();

exa(int v);

int getValue() { return value;}

int setValue(int v) { value = v;} }

exa::exa() {

value = 0;

int *arr = nullptr; }

exa::exa(int v)

{ value = v;

int *arr = new int[value]; }

3. Consider the following two class implementations. Is the integer array part of the member data?

class exa

{

private:

int value;

int *arr;

public:

exa();

exa(int v);

int getValue() { return value;}

int setValue(int v) { value = v;}

} exa::exa()

{

value = 0;

int *arr = nullptr;

}

exa::exa(int v)

{

value = v;

int *arr = new int[value];

}

4. Consider the following two class implementations. Is the integer array part of the member data?

class exa

{

private:

int value;

int *arr;

public:

exa();

exa(int v);

int getValue() { return value;}

int setValue(int v) { value = v;}

}

exa::exa()

{

value = 0;

*arr = nullptr;

}

exa::exa(int v)

{

value = v;

*arr = new int[value];

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Discuss termination of employees at various levels.

Answered: 1 week ago

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago