给我写一个C语言的代码 关于:电脑报价系统 主界面以菜单的形式展现,用户可以按不同的键执行不同的操作,即调用不同的函数; 用不同的函数实现,除以下模块,还可设计其他功能模块: 1)输入记录:电脑部件信息包括:编号、部件名、价格、型号,厂商、报价时间等; 2)输出记录:输出信息; 3)查询记录:可根据编号查找记录;4)删除记录:指定编号删除该条记录;5)插入记录:在指定位置插入新的记录。6)保存:将最后结果写入文件保存。
时间: 2023-03-19 13:21:42 浏览: 44
以下是一个简单的电脑报价系统的 C 语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 100 // 电脑部件信息最大长度
struct Computer {
int id;
char name[MAX_LEN];
float price;
char model[MAX_LEN];
char manufacturer[MAX_LEN];
char date[MAX_LEN];
};
struct Node {
struct Computer data;
struct Node *next;
};
struct Node *head = NULL; // 链表头指针
// 函数声明
void print_menu();
void insert();
void print();
void search();
void del();
void save();
void clear();
int main() {
int choice;
while (1) {
print_menu(); // 输出主界面
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
insert();
break;
case 2:
print();
break;
case 3:
search();
break;
case 4:
del();
break;
case 5:
clear();
break;
case 6:
save();
break;
case 7:
exit(0); // 退出程序
default:
printf("无效的选择,请重新输入!\n");
}
}
}
// 输出主界面
void print_menu() {
printf("\n");
printf("================= 电脑报价系统 =================\n");
printf("1. 输入记录\n");
printf("2. 输出记录\n");
printf("3. 查询记录\n");
printf("4. 删除记录\n");
printf("5. 清空记录\n");
printf("6. 保存记录\n");
printf("7. 退出程序\n");
printf("===============================================\n");
}
// 插入记录
void insert() {
struct Computer computer;
struct Node *node = (struct Node*)malloc(sizeof(struct Node));
if (node == NULL) {
printf("内存分配失败!\n");
return;
}
printf("请输入电脑部件信息:\n");
printf("编号:");
scanf("%d", &computer.id);
printf("部件名:");
scanf("%s", computer.name);
printf("价格:");
scanf("%f", &computer.price);
printf("型号:");
scanf("%s", computer.model);
printf("厂商:");
scanf("%s", computer.manufacturer);
printf("报价时间:");
scanf("%s", computer.date);
node->data = computer;
node->next = head;
head = node;
printf("记录插入成功!\n");
}
// 输出记录
void print() {
struct Node *p = head;
printf("编号\t部件名\t\t价格\t型号\t\t厂商\t\t报价时间\n");
while (p != NULL) {
printf("%d\t%s\t\t%.2f\t%s\t%s\t%s\n", p->data.id, p->data.name, p->data.price, p->data.model, p->data.manufacturer, p->data.date);
p = p->next;
}
}
// 查询记录
void search() {
int id;
printf("请输入要查询的电脑部件编号:");
scanf("%d", &id);
struct Node *p = head;
while (p != NULL
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)