Question

In: Computer Science

Must be written in c++ Must display comments Write a program that will read monthly sales...

Must be written in c++

Must display comments

Write a program that will read monthly sales into a dynamically allocated array allocated array of double values.

Your program should:
- prompt the user to enter the size of the array ( that is the number of monthly sales)
- dynamically allocate an array large enough to hold the number of monthly sales given
by the user
- find and print the yearly sum of all the monthly sales


Note: don’t forget to deallocate memory!

Sample Run:

Enter the number of monthly sales to be input: 4
Enter the monthly sales for month 1: 1290.89
Enter the monthly sales for month 2: 905.95
Enter the monthly sales for month 3: 1567.98
Enter the monthly sales for month 4: 994.83
The total sales for the year is: $4759.65

Solutions

Expert Solution

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<iostream>

using namespace std;

//sutting up prototypes

double findYearlySum(double sales[],int n);


//main function

int main()

{

//declaration

double *sales;

int arraysize;

cout<<"Enter the number of monthly sales to be input: ";

cin>>arraysize;

//dynamic creation of array

sales=new double[arraysize];

cout<<"Enter Monthly Sales"<<endl;

//reading monthly sales

for(int i=0;i<arraysize;i++)
{
cout<<"Enter the monthly sales for month "<<(i+1)<<": ";
cin>>sales[i];
}
//calling yearly sum function

double sum=findYearlySum(sales,arraysize);

//calling average function


//display result

cout<<"The total sales for the year is: $"<<sum<<endl;

delete sales
;

}//end of main

//function definition for finding sum

double findYearlySum(double *sales,int n)

{

double sum=0;

for(int i=0;i<n;i++)

sum +=sales[i];

return(sum);

}

Kindly revert for any queries

Thanks.


Related Solutions

The program should be written in C++ with comments Write a program that takes graduation rates...
The program should be written in C++ with comments Write a program that takes graduation rates (per 1000 of the population) for North, South, East, West and Central United States. Input the number from each of the regions in a function returning an int with the graduation rate to the main program. Also figure out which region has the highest graduation rate in another function and display the result from inside that particular function. So your function prototypes should be...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written using user-defined functions must take at least 1 argument Output number of months, payment, interest to pay, principle to pay, and ending balance
IN C++: Write a program to display the following table. MUST use for-loop Enter the table...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table size: 10 N N^2 Square root of N --------------------------------------------- 1 1 1.00 2 4 1.41 3 9 1.73 ….. 10 100 3.16
Write a C++ program to display toy name
Write a C++ program to display toy name
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
Write a program that will read a line of text. Display all the letters that occure...
Write a program that will read a line of text. Display all the letters that occure in the text, one per line and in alphabetical order, along with the number of times each letter occurs in the text. Use an array of base type int of length 26, so that the element at index 0 contains the number of a’s, the element at index 1 contains the number of b’s, and so forth, Alloow both upperCase and lower Case. Define...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
For your first project, write a C program (not a C++ program!)that will read in a...
For your first project, write a C program (not a C++ program!)that will read in a given list of non-negative integers and a target integer and checks if there exist two integers in the list that sum up to the target integer. Example:List: 31, 5, 8, 28, 15, 21, 11, 2 Target: 26 Yes!, 44 No! your C program will contain the following: •Write a function that will make a copy of the values from one array to another array....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT