Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started