Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that asks the user to input and integer named numDoubles. Cr

ID: 3769548 • Letter: W

Question

Write a C++ program that asks the user to input and integer named numDoubles. Create a dynamic array that can store numDoubles doubles and make a loop that allows the user to enter a double into each array entry. Loop through the array, calculate the average, and output it. DELETE THE MEMORY ALLOCATED TO THE ARRAY BEFORE EXITING.

Write the code for a C++ function that takes a pointer to an integer as parameter and adds 3 to the integer referenced by the parameter. The header for the function the function is as follows:

void addThree(int *ptr)

Add code to the main function to do the following. Define an int variable and give it a value, call addThree, and output the variable. It should be incremented by 3.

Explanation / Answer

Program:

Sample output:

Code to copy:

#include <iostream>

using namespace std;

int main()

{

     int numDoubles,i=0;

     double *doublesArray;

     double avg=0,sum=0;

     cout<<"Enter the number of double values do you want to enter: ";

     cin>>numDoubles;

     doublesArray=new double[numDoubles];

     cout<<"Enter "<<numDoubles<<" double values: "<<endl;

     //reading values

     while(i<numDoubles)

     {

          cin>>*(doublesArray+i);

          i++;

     }

     //calculating average

     for(i=0;i<numDoubles;i++)

     {

          sum+=*(doublesArray+i);

     }

     cout<<"Average of the given doubles="<<(double)(sum/numDoubles)<<endl;

     system("pause");

     return 0;

}

Program:

Sample output:

Code to copy:

#include <iostream>

using namespace std;

void addThree(int *);

int main()

{

     int number;

     cout<<"Enter a number: ";

     cin>>number;

     cout<<"The given number after adding 3 is ";

     addThree(&number);

     system("pause");

     return 0;

}

//adds 3 to the integer refereced by ptr

void addThree(int *ptr)

{

     cout<<*ptr+3<<endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote