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
Write a C++ program that asks the user for the values of three resistances. We suppose...
Write a C++ program that asks the user for the values of three resistances. We suppose that the user will not enter a negative value. The program then asks the user whether he has a series or parallel montage. The user will answer with S or s for series and P and p for parallel. (If the user enters a wrong answer, he will see a message on the screen alerting him, and the program will end.) Finally, the program...
In this project you will be writing a C++ program that uses a stack to convert...
In this project you will be writing a C++ program that uses a stack to convert an evaluate infix expression. Compilers often use this type of parsing. Note that the infix expression might not be syntactically correct. Before evaluating an infix expression, you need to check if its balanced, then convert it to a postfix expression then finally evaluate the postfix. You need to implement three methods: 1. public static Boolean checkBalance(String infixExpression) 2. public static String convertToPostfix(String infixExpression) 3....
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.
Encode Diffie Hellamn exchange in software by writing a small program that accepts the values of...
Encode Diffie Hellamn exchange in software by writing a small program that accepts the values of p and g, and randomly generates the secret numbers SA and SB, and derives the Diffie Hellman secret. Test it on the following examples: p = 11, g = 13 p = 7, g = 17 p = 17, g = 13
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);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT