50 D ATT LTE 1052 AM Expert QA Done C programming The ABC CO
Solution
#include<iostream>
#include<stdio.h>
using namespace std;
int no, p[100][4], ip[100];
float avi[100];
char name[100][10];
//Accepts item information
void acc()
{
int c, d;
cout<<\"\ Enter number of items: \";
cin>>no;
for(c = 0; c < no; c++)
{
cout<<\"\ Enter Item \"<<c+1<<\" Name: \";
cin>>name[c];
fflush(stdin);
//Accepts quarter data
for(d = 0; d < 4; d++)
{
cout<<\"\ Enter Item \"<<c+1<<\" Profit / Loss Data: \";
cin>>p[c][d];
}
}
}
//Displays the item information
void disp()
{
int c, d;
for(c = 0; c < no; c++)
{
cout<<name[c]<<\": \";
//Displays each quarter information
for(d = 0; d < 4; d++)
cout<<p[c][d]<<\" \";
cout<<endl;
}
}
//Displays total profit of each item and average profit of each item with company profit
void statement()
{
int c, d, tp = 0;
for(c = 0; c < no; c++)
{
ip[c] = 0; avi[c] = 0;
for(d = 0; d < 4; d++)
{
tp = tp + p[c][d];
ip[c] = ip[c] + p[c][d];
}
//calculates average profit
avi[c] = (float)ip[c] / 4;
}
//Displays information
for(c = 0; c < no; c++)
{
cout<<\"\ Total profit of Item: \"<<name[c]<<\" = \"<<ip[c];
cout<<\"\ Average profit of Item: \"<<name[c]<<\" = \"<<avi[c];
}
cout<<\"\ Total profit of the company: \"<<tp;
}
//Most profit in each quarter
void mostProfit()
{
int c, d, qa, pr, big = 0;
for(c = 0; c < 4; c++)
{
for(d = 0; d < no; d++)
{
//find out the biggest profit
if(big < p[d][c])
{
big = p[d][c];
pr = d;
qa = c;
}
}
big = 0;
cout<<\"\ Quarter Number: \"<<c+1<<\" \ Item Name: \"<<name[pr]<<\"\ Profit: \"<<p[pr][qa];
}
}
//Displays number of profit and loss
void numProfitLoss()
{
int c, d, np, nl;
for(c = 0; c < 4; c++)
{
np = nl = 0;
for(d = 0; d < no; d++)
{
if(p[d][c] > 0)
//count for number of profit
np++;
else
//count for number of loss
nl++;
}
cout<<\"\ Quarter Number: \"<<c+1<<\" Number of Profit: \"<<np<<\" Number of Loss: \"<<nl;
}
}
//Displays Item status
void status()
{
int c, d = 0;
for(c = 0; c < no; c++)
{
if(p[c][d] < p[c][d+1] && p[c][d+1] < p[c][d+2] && p[c][d+2] < p[c][d+3] )
cout<<\"\ Item \"<<name[c]<<\" is steadily increasing\";
else if(p[c][d] > p[c][d+1] && p[c][d+1] > p[c][d+2] && p[c][d+2] > p[c][d+3] )
cout<<\"\ Item \"<<name[c]<<\" is steadily decreasing\";
else
cout<<\"\ Item \"<<name[c]<<\" went up and down\";
}
}
int main()
{
acc();
cout<<\"\ Item Information \ \";
disp();
cout<<\"\ Status of the Item \ \";
statement();
cout<<\"\ Most profit item in a quarter \ \";
mostProfit();
cout<<\"\ Number of profit and number of loss \ \";
numProfitLoss();
cout<<\"\ Status of each item \ \";
status();
}
Output:
Enter number of items: 3
Enter Item 1 Name: a
Enter Item 1 Profit / Loss Data: -10
Enter Item 1 Profit / Loss Data: -20
Enter Item 1 Profit / Loss Data: -40
Enter Item 1 Profit / Loss Data: 90
Enter Item 2 Name: b
Enter Item 2 Profit / Loss Data: -10
Enter Item 2 Profit / Loss Data: 30
Enter Item 2 Profit / Loss Data: 60
Enter Item 2 Profit / Loss Data: 70
Enter Item 3 Name: c
Enter Item 3 Profit / Loss Data: 50
Enter Item 3 Profit / Loss Data: 30
Enter Item 3 Profit / Loss Data: -10
Enter Item 3 Profit / Loss Data: -30
Item Information
a: -10 -20 -40 90
b: -10 30 60 70
c: 50 30 -10 -30
Status of the Item
Total profit of Item: a = 20
Average profit of Item: a = 5
Total profit of Item: b = 150
Average profit of Item: b = 37.5
Total profit of Item: c = 40
Average profit of Item: c = 10
Total profit of the company: 210
Most profit item in a quarter
Quarter Number: 1
Item Name: c
Profit: 50
Quarter Number: 2
Item Name: b
Profit: 30
Quarter Number: 3
Item Name: b
Profit: 60
Quarter Number: 4
Item Name: a
Profit: 90
Number of profit and number of loss
Quarter Number: 1 Number of Profit: 1 Number of Loss: 2
Quarter Number: 2 Number of Profit: 2 Number of Loss: 1
Quarter Number: 3 Number of Profit: 1 Number of Loss: 2
Quarter Number: 4 Number of Profit: 2 Number of Loss: 1
Status of each item
Item a went up and down
Item b is steadily increasing
Item c is steadily decreasing



