134k views
4 votes
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 salesperson or the sales on a particular product

User Makach
by
5.8k points

1 Answer

5 votes

Answer:

See Explaination

Step-by-step explanation:

#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 \\2. Product 2 \\3. Product 3 \\4. Product 4 \\5. Product 5 \\";

//prompt for product

cout<<"Enter Product: ";

cin>>product;

cout<<"1. Sales Person 1 \\2. Sales Person 2 \\3. Sales Person 3 \\4. Sales Person 4 \\";

//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 \\2. Sales Person 2 \\3. Sales Person 3 \\4. Sales Person 4 \\";

//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 \\";

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

{

cout<<"Product "<<i+1<<": "<<sales[i][person-1]<<"\\";

total=total+sales[i][person-1];

}

//printing total sales by a person

cout<<"Total: "<<total<<"\\";

}

else

{

cout<<"Error!\\";

}

}

//function to check sales by a product

void Check_product(int sales[5][4])

{

int product,total=0;

cout<<"1. Product 1 \\2. Product 2 \\3. Product 3 \\4. Product 4 \\5. Product 5 \\";

//prompt for product

cout<<"Enter Product: ";

cin>>product;

if(product>=1 && product<=5)

{

//printing details of sales on a product

cout<<"Details of Sales \\";

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

{

cout<<"Sales Person "<<i+1<<": "<<sales[product-1][i]<<"\\";

total=total+sales[product-1][i];

}

//printing total sales on a product

cout<<"Total: "<<total<<"\\";

}

else

{

cout<<"Error!\\";

}

}

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\\2. Check Sales by a Person\\3. Check Sales on a Product\\4. Exit\\";

//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!\\";

break;

}

}

}

User Dkong
by
5.2k points