Untitled
unknown
plain_text
a year ago
4.1 kB
3
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Branch {
char b_id[50];
char m_id[50];
float sales[12];
};
void print_menu();
void input_data(struct Branch br[], int size);
float total_sales(struct Branch br[], int size);
void sale_percentage(struct Branch br[], int size);
void peak_sales(struct Branch br[], int size);
void bubble_sort(float arr[], int size);
void display_month(struct Branch br[], int size, int month);
void display_branch(struct Branch br[], int size, int branch);
int main () {
int size = 2;
int input;
int while_flag = 1;
float total;
int month;
int branch;
struct Branch br[size];
while(while_flag) {
print_menu();
printf("Enter your choice: ");
scanf("%d", &input);
switch(input) {
case 1:
input_data(br, size);
break;
case 2:
total = total_sales(br, size);
printf("Total Sales = %0.2f\n", total);
break;
case 3:
sale_percentage(br, size);
break;
case 4:
peak_sales(br, size);
break;
case 5:
printf("Enter Month: ");
scanf("%d", &month);
display_month(br, size, month-1);
break;
case 6:
printf("Enter Branch: ");
scanf("%d", &branch);
display_branch(br, size, branch-1);
break;
case 7:
while_flag = 0;
break;
default:
printf("\nEnter between 1 - 7\n");
}
system("pause");
system("cls");
}
return 0;
}
void print_menu() {
printf("1. Enter Branch Data\n");
printf("2. Calculate Total Sales\n");
printf("3. Calculate percentage of sales\n");
printf("4. Month of Peak Sales\n");
printf("5. Display Month Sales in Order\n");
printf("6. Display Branch Sales in Order\n");
printf("7. Exit\n\n");
}
void input_data(struct Branch br[], int size) {
int i, j;
for (i = 0; i < size; i++) {
getchar();
printf("Enter Branch %d/%d ID: ", i+1, size);
gets(br[i].b_id);
printf("Enter Manager %d/%d ID: ", i+1, size);
gets(br[i].m_id);
for (j = 0; j < 12; j++) {
printf(">> Enter Branch %d/%d Sales of Month %d: ", i+1, size, j+1);
scanf("%f", &br[i].sales[j]);
}
}
}
float total_sales(struct Branch br[], int size) {
int i, j;
float sum = 0;
for (i = 0; i < size; i++) {
for (j = 0; j < 12; j++) {
sum = sum + br[i].sales[j];
}
}
return sum;
}
void sale_percentage(struct Branch br[], int size) {
int i, j;
float sum = 0;
float total = total_sales(br, size);
for (i = 0; i < size; i++) {
for (j = 0; j < 12; j++) {
sum = sum + br[i].sales[j];
}
printf("Percentage of Branch %d = %0.1f%%\n", i+1, (sum * 100) / total);
sum = 0;
}
}
void peak_sales(struct Branch br[], int size) {
int i, j;
float sum = 0;
float total = total_sales(br, size);
float month_sales[12];
int max_month = 0;
for (j = 0; j < 12; j++) {
for (i = 0; i < size; i++) {
sum = sum + br[i].sales[j];
}
month_sales[j] = sum;
sum = 0;
}
for (i = 0; i < 12; i++) {
if (month_sales[i] > month_sales[max_month]) {
max_month = i;
}
}
printf("Max Sales in Month %d = %0.2f\n", max_month+1, month_sales[max_month]);
}
void bubble_sort(float arr[], int size) {
int i, j;
float temp;
for (i = 1; i < size; i++) {
for (j = 0; j < size-i; j++) {
if (arr[j] < arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
void display_month(struct Branch br[], int size, int month) {
int i;
float branch_sales[size];
for (i = 0; i < size; i++) {
branch_sales[i] = br[i].sales[month];
}
bubble_sort(branch_sales, size);
for (i = 0; i < size; i++) {
printf("Sales of Month %d in order = %0.2f\n", month+1, branch_sales[i]);
}
}
void display_branch(struct Branch br[], int size, int branch) {
int i;
float branch_sales[12];
for (i = 0; i < 12; i++) {
branch_sales[i] = br[branch].sales[i];
}
bubble_sort(branch_sales, 12);
for (i = 0; i < 12; i++) {
printf("Sales of Branch %d in order = %0.2f\n", branch+1, branch_sales[i]);
}
}Editor is loading...
Leave a Comment