# Quarterly sales report

In this project you will create a program that will calculate the quarterly sales for a company. You will be using two arrays to store the quarterly sales figures and the quarterly names Q1, Q2, Q3 and Q4. Since you will be dealing with money you will need to use a double datatype. The program will prompt the user for the quarterly sales figures for each quarter, Q1 through Q4. Here are some of the main variables you will need to create for the program:

• Quarter                   Is a string array that holds quarterly names “Q1”, “Q2”, “Q3”, and “Q4”.
• quarterlySales        Is an array that holds the quarterly sales for the year

Once you have gotten the quarterly sales numbers you will pass the quarterlySales array to the following functions:

• Function that will sum the quarterly sales and return the yearly sales
• Function that will average the quarterly sales and return the average quarterly sales
• Function that will return the index (subscript) of the quarter with the highest sales amount
• Function that will return the index (subscript) of the quarter with the lowest sales amount
• Function that will sort the array in ascending (lowest to highest) order 1, 2, 3, etc.

You should display:

• Total quarterly sales for the year
• Average quarterly sales for the year
• Quarter with the highest sales and the sales amount
• Quarter with the lowest sales and the sales amount
• Quarter sales sorted from lowest to highest. Display the quarter and the amount

Formatting the output: You will need to format all sales with a \$ and 2 decimal points precision.
Since you will be sorting a parallel array the code given as follows:

void sortAry(double qSales[], int size, string qName[])

{

bool swap;

double tempSales;

string tempDays;

do

{

swap = false;

for (int count = 0; count < (size – 1); count++)

{

if (qSales[count] > qSales[count + 1])

{

tempSales = qSales[count];

qSales[count] = qSales[count + 1];

qSales[count + 1] = tempSales;

tempDays = qName[count];

qName[count] = qName[count + 1];

qName[count + 1] = tempDays;

swap = true;

}

}

} while (swap);

}

Program Output:

This program calculates total quarterly sales.

The total quarterly sales for the year were: \$924711.04

The average quarterly sales for the year were: \$231177.76

The quarter with the highest sales amount was Q2 with a sales total of \$356242.58

The quarter with the lowest sales amount was Q4 with a sales total of \$120253.25

Quarterly sales sorted from lowest to highest:

Q4 had gross sales of \$120253.25

Q1 had gross sales of \$123652.36

Q3 had gross sales of \$324562.85

Q2 had gross sales of \$356242.58

Press any key to continue . . .

Solution

Main.java

package com.assignment;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

String[] Quarter = {“Q1”, “Q2”, “Q3”, “Q4”};

double[] qSales = new double;

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

{

System.out.println(“Please enter the gross sales received on ” + Quarter[i] + “: “);

qSales[i] = s.nextDouble();

}

System.out.println(“The total quarterly sales for the year were: \$”+ ySales(qSales, 4));

System.out.println(“The average quarterly sales for the year were: \$” + avgQSales(qSales, 4));

System.out.println(“The quarter with the highest sales amount was ” + Quarter[hSales(qSales, 4)] + ” with a sales total of \$” + qSales[hSales(qSales, 4)]);

System.out.println(“The quarter with the lowest sales amount was ” + Quarter[lSales(qSales, 4)] + ” with a sales total of \$” + qSales[lSales(qSales, 4)]);

System.out.println(“\n\n”);

System.out.println(“Quarterly sales sorted from lowest to highest:\n”);

sortAry(qSales, 4, Quarter);

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

{

System.out.println(Quarter[i] + ” had gross sales of \$” + qSales[i]);

}

}

public static double ySales(double qSales[], int size)

{

double sum = 0;

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

sum+=qSales[i];

return sum;

}

public static double avgQSales(double qSales[], int size)

{

return ySales(qSales, size)/4.0;

}

public static int hSales(double qSales[], int size)

{

int max = 0;

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

{

if(qSales[i]>qSales[max])

max = i;

}

return max;

}

public static int lSales(double qSales[], int size)

{

int min =  0;

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

{

if(qSales[i]<qSales[min])

min = i;

}

return min;

}

public static void sortAry(double qSales[], int size, String qName[])

{

boolean swap;

double tempSales;

String tempDays;

do

{

swap = false;

for (int count = 0; count < (size – 1); count++)

{

if (qSales[count] > qSales[count + 1])

{

tempSales = qSales[count];

qSales[count] = qSales[count + 1];

qSales[count + 1] = tempSales;

tempDays = qName[count];

qName[count] = qName[count + 1];

qName[count + 1] = tempDays;

swap = true;

}

}

} while (swap);

}

}

qSales.cpp

#include<iostream>

#include<iomanip>

using namespace std;

double ySales(double qSales[], int size)

{

double sum = 0;

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

sum+=qSales[i];

return sum;

}

double avgQSales(double qSales[], int size)

{

return ySales(qSales, size)/4.0;

}

int hSales(double qSales[], int size)

{

int max = 0;

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

{

if(qSales[i]>qSales[max])

max = i;

}

return max;

}

int lSales(double qSales[], int size)

{

int min =  0;

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

{

if(qSales[i]<qSales[min])

min = i;

}

return min;

}

void sortAry(double qSales[], int size, string qName[])

{

bool swap;

double tempSales;

string tempDays;

do

{

swap = false;

for (int count = 0; count < (size – 1); count++)

{

if (qSales[count] > qSales[count + 1])

{

tempSales = qSales[count];

qSales[count] = qSales[count + 1];

qSales[count + 1] = tempSales;

tempDays = qName[count];

qName[count] = qName[count + 1];

qName[count + 1] = tempDays;

swap = true;

}

}

} while (swap);

}

int main()

{

string Quarter = {“Q1”, “Q2”, “Q3”, “Q4”};

double qSales;

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

{

std::cin>>qSales[i];

}

std::cout<<std::fixed<<std::setprecision(2);    //setting the precision to 2

std::cout<<“\nThe total quarterly sales for the year were: \$”<<ySales(qSales, 4);

std::cout<<“\nThe average quarterly sales for the year were: \$”<<avgQSales(qSales, 4);

std::cout<<“\nThe quarter with the highest sales amount was “<<Quarter[hSales(qSales, 4)]<<” with a sales total of \$”<<qSales[hSales(qSales, 4)];

std::cout<<“\nThe quarter with the lowest sales amount was “<<Quarter[lSales(qSales, 4)]<<” with a sales total of \$”<<qSales[lSales(qSales, 4)];

std::cout<<endl<<“Quarterly sales sorted from lowest to highest:\n”<<std::endl;

sortAry(qSales, 4, Quarter);

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

{

std::cout<<Quarter[i]<<” had gross sales of \$”<<qSales[i]<<std::endl;

}

return 0;

}

qSales.txt

#include<iostream>

#include<iomanip>

using namespace std;

double ySales(double qSales[], int size)

{

double sum = 0;

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

sum+=qSales[i];

return sum;

}

double avgQSales(double qSales[], int size)

{

return ySales(qSales, size)/4.0;

}

int hSales(double qSales[], int size)

{

int max = 0;

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

{

if(qSales[i]>qSales[max])

max = i;

}

return max;

}

int lSales(double qSales[], int size)

{

int min =  0;

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

{

if(qSales[i]<qSales[min])

min = i;

}

return min;

}

void sortAry(double qSales[], int size, string qName[])

{

bool swap;

double tempSales;

string tempDays;

do

{

swap = false;

for (int count = 0; count < (size – 1); count++)

{

if (qSales[count] > qSales[count + 1])

{

tempSales = qSales[count];

qSales[count] = qSales[count + 1];

qSales[count + 1] = tempSales;

tempDays = qName[count];

qName[count] = qName[count + 1];

qName[count + 1] = tempDays;

swap = true;

}

}

} while (swap);

}

int main()

{

string Quarter = {“Q1”, “Q2”, “Q3”, “Q4”};

double qSales;

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

{

std::cin>>qSales[i];

}

std::cout<<std::fixed<<std::setprecision(2);    //setting the precision to 2

std::cout<<“\nThe total quarterly sales for the year were: \$”<<ySales(qSales, 4);

std::cout<<“\nThe average quarterly sales for the year were: \$”<<avgQSales(qSales, 4);

std::cout<<“\nThe quarter with the highest sales amount was “<<Quarter[hSales(qSales, 4)]<<” with a sales total of \$”<<qSales[hSales(qSales, 4)];

std::cout<<“\nThe quarter with the lowest sales amount was “<<Quarter[lSales(qSales, 4)]<<” with a sales total of \$”<<qSales[lSales(qSales, 4)];

std::cout<<endl<<“Quarterly sales sorted from lowest to highest:\n”<<std::endl;

sortAry(qSales, 4, Quarter);                //sorting the sales array

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

{

std::cout<<Quarter[i]<<” had gross sales of \$”<<qSales[i]<<std::endl;

}

return 0;

}