问题描述:
本代码比较完善,有菜单模块,拥有较高的可操控性和可观性。
代码所包含的功能有很多:输入销售数据,计算每人每种产品销售额,按销售额对销售员排序,计算每种产品总销售额,显示销售报表......
以下是全部代码:
记得点赞加关注喔~
#include <stdio.h>
#include <stdlib.h>
#define SALESMAN_COUNT 4
#define PRODUCT_COUNT 5
void inputSalesData(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
void calculateSalesBySalesmanAndProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
void sortSalesmenBySales(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
void calculateTotalSalesByProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
void displayMenu();
void displaySalesBySalesmanAndProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
void displaySortedSalesmen();
void displayTotalSalesByProduct();
void displaySalesReport(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]);
int main() {
int salesData[SALESMAN_COUNT][PRODUCT_COUNT] = {0};
int choice;
do {
displayMenu();
scanf("%d", &choice);
switch (choice) {
case 1:
inputSalesData(salesData);
break;
case 2:
calculateSalesBySalesmanAndProduct(salesData);
break;
case 3:
sortSalesmenBySales(salesData);
break;
case 4:
calculateTotalSalesByProduct(salesData);
break;
case 5:
displaySalesReport(salesData);
break;
case 6:
printf("正在退出...\n");
break;
default:
printf("无效选择。请重试。\n");
}
} while (choice!= 6);
return 0;
}
void displayMenu() {
printf("\n销售管理系统菜单:\n");
printf("1. 输入销售数据\n");
printf("2. 计算每人每种产品销售额\n");
printf("3. 按销售额对销售员排序\n");
printf("4. 计算每种产品总销售额\n");
printf("5. 显示销售报表\n");
printf("6. 退出\n");
printf("请输入你的选择: ");
}
void inputSalesData(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
int salesman, product, amount;
printf("输入销售员编号(1 - 4)、产品编号(1 - 5)和销售额: ");
scanf("%d %d %d", &salesman, &product, &amount);
salesData[salesman - 1][product - 1] += amount;
}
void calculateSalesBySalesmanAndProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
// 此函数用于计算上个月每个人每种产品的销售额,可在输入数据后调用或作为报表生成的一部分。目前只是占位符。
printf("每人每种产品销售额已计算。\n");
}
void sortSalesmenBySales(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
int totalSalesBySalesman[SALESMAN_COUNT];
for (int i = 0; i < SALESMAN_COUNT; i++) {
totalSalesBySalesman[i] = 0;
for (int j = 0; j < PRODUCT_COUNT; j++) {
totalSalesBySalesman[i] += salesData[i][j];
}
}
for (int i = 0; i < SALESMAN_COUNT - 1; i++) {
for (int j = i + 1; j < SALESMAN_COUNT; j++) {
if (totalSalesBySalesman[i] < totalSalesBySalesman[j]) {
int temp = totalSalesBySalesman[i];
totalSalesBySalesman[i] = totalSalesBySalesman[j];
totalSalesBySalesman[j] = temp;
}
}
}
printf("按销售额从高到低排序的销售员编号: ");
for (int i = 0; i < SALESMAN_COUNT; i++) {
printf("%d ", i + 1);
}
printf("\n");
}
void calculateTotalSalesByProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
int totalSalesByProduct[PRODUCT_COUNT];
for (int i = 0; i < PRODUCT_COUNT; i++) {
totalSalesByProduct[i] = 0;
for (int j = 0; j < SALESMAN_COUNT; j++) {
totalSalesByProduct[i] += salesData[j][i];
}
}
printf("每种产品总销售额:\n");
for (int i = 0; i < PRODUCT_COUNT; i++) {
printf("产品 %d 的总销售额:%d\n", i + 1, totalSalesByProduct[i]);
}
}
void displaySalesBySalesmanAndProduct(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
printf("每人每种产品销售额:\n");
for (int i = 0; i < SALESMAN_COUNT; i++) {
for (int j = 0; j < PRODUCT_COUNT; j++) {
printf("销售员 %d,产品 %d 的销售额:%d\n", i + 1, j + 1, salesData[i][j]);
}
}
}
void displaySortedSalesmen() {
// 此函数用于显示按销售额排序后的销售员,可在对销售员排序后调用。目前只是占位符。
printf("排序后的销售员已显示。\n");
}
void displayTotalSalesByProduct() {
// 此函数用于显示每种产品的总销售额,可在计算每种产品总销售额后调用。目前只是占位符。
printf("每种产品总销售额已显示。\n");
}
void displaySalesReport(int salesData[SALESMAN_COUNT][PRODUCT_COUNT]) {
printf("销售统计报表:\n");
printf("销售员编号\t产品1\t产品2\t产品3\t产品4\t产品5\t销售总和\n");
for (int i = 0; i < SALESMAN_COUNT; i++) {
int totalSales = 0;
printf("%d\t\t", i + 1);
for (int j = 0; j < PRODUCT_COUNT; j++) {
printf("%d\t\t", salesData[i][j]);
totalSales += salesData[i][j];
}
printf("%d\n", totalSales);
}
printf("产品编号\t每种产品总和\n");
for (int i = 0; i < PRODUCT_COUNT; i++) {
int totalSales = 0;
for (int j = 0; j < SALESMAN_COUNT; j++) {
totalSales += salesData[j][i];
}
printf("%d\t\t%d\n", i + 1, totalSales);
}
}
运行结果:
标签:COUNT,PRODUCT,管理系统,int,salesData,C语言,实训,printf,SALESMAN From: https://blog.csdn.net/qq_49964423/article/details/143251508