Question

In: Computer Science

Suppose we are writing a C++ program for the sales department of a small company. The...

Suppose we are writing a C++ program for the sales department of a small company. The department has 4 sales person and is selling 5 products. The program will allow the input of each sale made (sales person, product, sales amount). The program will also allow a user to see the sales made by a particular sales person or the sales on a particular product.

Requirement of the Program:

1. Using a 2-D array as a data structure for storing the sales information

2. Containing a menu that allows a user to

1. Enter a sale
2. Check the sales made by a sales person
3. Check the sales on a product
4. Exit the program

Here is a sample run of the program:


Solutions

Expert Solution

Answer : Given data

CODE

#include<iostream>
using namespace std;

//function to enter sales
void Enter_sale(int sales[5][4])
{
   //variables
   int product,person,sale_amount;
  
   cout<<"1. Product 1 \n2. Product 2 \n3. Product 3 \n4. Product 4 \n5. Product 5 \n";
  
   //prompt for product
   cout<<"Enter Product: ";
   cin>>product;
  
   cout<<"1. Sales Person 1 \n2. Sales Person 2 \n3. Sales Person 3 \n4. Sales Person 4 \n";
  
   //prompt for sales
   cout<<"Enter Sales Person: ";
   cin>>person;
  
   //prompt for sales amount
   cout<<"Enter Sales Amount: ";
   cin>>sale_amount;
  
   //adding to previous total sales amount
   sales[product-1][person-1]=sales[product-1][person-1]+sale_amount;
}

//function to check sales by a person
void Check_salesperson(int sales[5][4])
{
   int person,total=0;
   cout<<"1. Sales Person 1 \n2. Sales Person 2 \n3. Sales Person 3 \n4. Sales Person 4 \n";
  
   //prompt for person
   cout<<"Enter Sales Person: ";
   cin>>person;
  
   if(person>=1 && person<=4)
   {
       //printing details of sales by a person
       cout<<"Details of Sales \n";
       for(int i=0;i<5;i++)
       {
           cout<<"Product "<<i+1<<": "<<sales[i][person-1]<<"\n";
           total=total+sales[i][person-1];
       }
       //printing total sales by a person
       cout<<"Total: "<<total<<"\n";
   }
   else
   {
       cout<<"Error!\n";
   }
}

//function to check sales by a product
void Check_product(int sales[5][4])
{
   int product,total=0;
   cout<<"1. Product 1 \n2. Product 2 \n3. Product 3 \n4. Product 4 \n5. Product 5 \n";
  
   //prompt for product
   cout<<"Enter Product: ";
   cin>>product;
   if(product>=1 && product<=5)
   {
       //printing details of sales on a product
       cout<<"Details of Sales \n";
       for(int i=0;i<4;i++)
       {
           cout<<"Sales Person "<<i+1<<": "<<sales[product-1][i]<<"\n";
           total=total+sales[product-1][i];
       }
       //printing total sales on a product
       cout<<"Total: "<<total<<"\n";
   }
   else
   {
       cout<<"Error!\n";
   }
}

int main()
{
   int choice;
   int sales[5][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
   while(true)
   {
       //Menu
       cout<<"1. Enter Sales\n2. Check Sales by a Person\n3. Check Sales on a Product\n4. Exit\n";
      
       //choice
       cin>>choice;
       switch(choice)
       {
           //if enter sales
           case 1:
               Enter_sale(sales);
               break;
           //if check sales by a person
           case 2:
               Check_salesperson(sales);
               break;
           //if check sales on a product
           case 3:
               Check_product(sales);
               break;
           //if exit
           case 4:
               exit(0);
           //if wrong choice
           default:
               cout<<"Error!\n";
               break;
       }
   }
}

OUTPUT

CODE SCREEN SHOT

____________THE END_____________


Related Solutions

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”...
write a report about travel agency in c++ not a program writing just report writing
write a report about travel agency in c++ not a program writing just report writing
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
Write a C program that opens a file called "numbers.txt" in writing mode. The program should...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should then read floating point numbers from the keyboard, and write these lines to the opened file one per line, stopping when the number 0 is entered. Your program should check to make sure that the file was opened successfully, and terminate if it was not.
You are writing a small program that records a swimmers swim time for a 100 Free...
You are writing a small program that records a swimmers swim time for a 100 Free Style event, compares it to the best time, and displays back if swimmer improved or added time. The swim time is entered in seconds. Prompt user to enter their best time before an event and current swim time and then display message if user improved or added time and by how many seconds. It's c++ program and use iostream header.
You will be writing a C program to test the data sharing ability of a thread...
You will be writing a C program to test the data sharing ability of a thread and process. Your C program will do the following: 1. Your parent program will have three variables: int x,y,z; which to be initialized as 10, 20, and 0, respectively. 2. parent creating child: parent will create a child by fork() and the child will perform z = x+y (i.e., add x and y and store the results in z). parent will wait for child...
This is c++. The goal is to test each method function by writing a simple program...
This is c++. The goal is to test each method function by writing a simple program displaying how they work in int main . #ifndef ARRAY_FUNCTIONS_H #define ARRAY_FUNCTIONS_H #include <iostream> #include <iomanip> using namespace std; template <typename T> class Array_functions { public: int size; int cap; int* ptr; //default ctor Array_functions(); // ctor with one arg Array_functions(int size); //allactes a dynamic array T* allocate(int n); //resizes array onto another T* resize_arr(T *dest,int old_cap, int new_cap); //deletes array void delete_arr(T& a);...
Writing a squareroot program in C++ using only: #include <iostream> using namespace std; The program must...
Writing a squareroot program in C++ using only: #include <iostream> using namespace std; The program must be very basic. Please don't use math sqrt. Assume that the user does not input anything less than 0. For example: the integer square root of 16 is 4 because 4 squared is 16. The integer square root of 18 is 5 because 4 squared is 16 and 5 squared is 25, so 18 is bigger than 16 but less than 25.  
Writing an nth root program in C++ using only: #include using namespace std; The program must...
Writing an nth root program in C++ using only: #include using namespace std; The program must be very basic. Please don't use math sqrt or pow . For example, the 4th root of 16 is 2 because 2 * 2 * 2 * 2 = 16. The 4th root of 20 is 2 because 2 * 2 * 2 * 2 = 16 and 16 is less than 20, and 3 * 3 * 3 * 3 = 81, which...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT