Question

In: Computer Science

Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...

Program Assignment 1

C++ please

Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names. A second array will be used for the price of each bottle of BBQ sauce; this will also be initialized from a file. The two files can be different files. The third array will be used to store the amount sold of each type of sauce. The program will then prompt the user for how many of each sauce has been sold. Once all the data is entered a report is created that displays each of the sauce types with the total amount sold and the total sales for each of the sauces. This output should be in a table format. The program will also calculate the overall total of sales for all of the sauces. It will then determine which sauce was the highest selling and the lowest selling product.

Validations:

1.) The files can be opened

2.) No negative values for the amount of sales for each sauce. This should be a loop asking for the input again.

Requirements:

1. When prompting for the amount sold of a sauce, the name of the sauce must be used in the prompt.

2. Table output should have evenly spaced columns.

3. Where there is currency being displayed, it must be formatted with 2 decimal places and a $.

4. Method to display the table of output.

5. Method to calculate the total of overall sales, returns the amount.

6. Method to get the inputs from the user for the amount sold of each sauce.

7. Method to determine which is the highest and lowest product sold.

Solutions

Expert Solution

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
//method to print the details in tabular format
void print(string name[],int sale[],double price[])
{
    int i;

cout<<endl<<"==============================================================================";
cout<<endl<<"Names of Sauce\t\tTotal Amount Sold\t\tTotal Sales";
cout<<endl<<"==============================================================================";
for(i=0;i<6;i++)
{
    if(name[i].length()<6) //condition to maintain the uniform space
       cout<<endl<<name[i]<<"\t\t\t\t"<<sale[i]<<"\t\t\t$"<<fixed<<setprecision(2)<<sale[i]*price[i];
       else
    cout<<endl<<name[i]<<"\t\t\t"<<sale[i]<<"\t\t\t$"<<fixed<<setprecision(2)<<sale[i]*price[i];
}
  
}
//method to return the total number of sales done
int totalsale(int sale[])
{
    int i,total=0;
    for(i=0;i<6;i++)
    total = total + sale[i]; //compute the total sale
    return total; //return the total sale
}
//method to input the amount of items sold
void amountsold(string name[],int sale[])
{
   int i;
   for(i=0;i<6;i++)
{
    cout<<endl<<"Enter the amount of sold for "<<name[i]<<" Sauce";
    cin>>sale[i]; //input the sale
    if(sale[i]<0) //validate the sale
    i--;
}
}
//method to display the highest and lowest sale
void highlow(string name[],int sale[])
{
    int i,mi,ma,min,max;
    min=sale[0]; //assign the first value as min sale
    max=sale[0];//assign the first value as max sale
    for(i=0;i<6;i++)
    {
       if(min>sale[i]) //condition to find the min sale
       {
       min=sale[i]; //assign min sale to min
          mi=i;//assign the index to mi
           }
       if(max<sale[i])     
       {
       max=sale[i]; //assign max sale to min
          ma=i;//assign the index to ma
       }
       }
       //display the result
       cout<<endl<<name[mi]<<" Sold less quantity";
       cout<<endl<<name[ma]<<" Sold high quantity";
}
//driver program
int main()
{
    string name[6],str;
    double price[6],p;
    int sale[6],i,j;
    //declare file objects
    ifstream infile1,infile2;
   //open the name file in read mode
   infile1.open("D:/names.txt");
   //if not open
   if(!infile1)
   {
      cout<<endl<<"Unable to open the source file";
          exit(0);
   }
     
   //open the price file in read mode
   infile2.open("D:/price.txt");
   //if not open
   if(!infile2)
   {
      cout<<endl<<"Unable to open the source file";
          exit(0);
   }
   //loop to read the names and store it name array
   i=0;
   while (getline(infile1, str)) {
name[i]=str;
i++;
}
//loop to read the price and store it in price array
   i=0;
   while(! infile2.eof())
       {
           infile2>>p;
price[i]=p;
i++;
}
  
  
//call to amountsold() to input the sale amount
amountsold(name,sale);
//call to print() to print in tabular format
print(name,sale,price);
//call to totalsale() to display the total sale
j=totalsale(sale);
//display the total sale
cout<<endl<<"Total sale : "<<j;
//method call to display the highest and lowest sale
highlow(name,sale);
  
  
  
}

OUTPUT

VALUE OF NAME AND PRICE FILE


Related Solutions

This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
Instructions: program in C++, add pseudocode and comment throughout the program. Assignment: Create a program to...
Instructions: program in C++, add pseudocode and comment throughout the program. Assignment: Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write a program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop 10 questions that you would ask a management official responsible for the financial planning for the organization you have chosen to research for the week 3 paper. 2. Make sure the questions will give you insight into what the company looks for when preparing their yearly budget, fiscal planning strategies, as well as how they monitor their financial condition throughout the year and make...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array which can store up to 50 student names where a name is up to 25 characters long - an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array which can store up to 50 student names where a name is up to 25 characters long - an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT