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

Write a program that will read monthly sales into a dynamically allocatedarray.

ID: 3618728 • Letter: W

Question

Write
a program that will read monthly sales into a dynamically allocatedarray. The
program will input the size of the array from the user. Itwill call a function that will find the
yearly sum (the sum of all the sales). It will also call anotherfunction that
will find the average.

What I have:

#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>

float* sales;
int count;
int clrscr;

float yearlySum()
{
    float sum = 0.0;
    for(int i=0;i<count;i++)
    {
        sum = sum +sales[i];
    }
    return sum;
}

float average()
{   
    return yearlySum()/(count+1);;
}


void printSource()
{
    clrscr();
     cout << " Elements in the sourcearray : "<<endl;
    for(int i=0;i<count;i++)
    {
        printf("%.2f  ",sales[i]);
    }
    cout<<" "<<endl;
}

int main()
{           
    char yesno = 'n';
    count = 0;
    do
    {
        cout << " Entersales for a month :"<<endl;
       cin>>sales[count]>>endl;
        count++;

        cout << " Do youwant to enter another ID number(Y/N) : "<<endl;
       cin>>yesno>>endl;
    }while(yesno == 'y' || yesno == 'Y');

     printSource();

     printf(" Yearly Sum of sales :%.2f",yearlySum());
     printf(" Avearge sales :%.2f",average());
   
    return 0;
}

Explanation / Answer

#include #include int calculate_sum(int *,int); void calculate_average(int,int); void main() { clrscr(); int size; printf(" Enter the size of the array :"); scanf("%d",&size); int *ptr=new int[size]; printf(" Input to the array "); for(int i=0;i
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