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...
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...
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...
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...
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,...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following:...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following: (1) the client and the server source files each (2) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identifiers suitable, to enable enhanced readability of the code. Problem: Write an ftp client and an ftp server such that the client sends a request to ftp server for downloading a file. The...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
I have this program in C that takes three char arrays that each have a first...
I have this program in C that takes three char arrays that each have a first and last name. I have two functions that reverese the name and change it to all upper case. I have the program completeed but need to change both functions to use pointers instead of arrays. I will bold the functions I need to use pointers. #include <stdio.h> void upper_string(char []); int main() { char name1[100]="John Smith"; char name2[100]="Mary Cohen"; char name3[100]="Carl Williams"; upper_string(name1);// calling...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT