1 实验描述 1.1 实验目的 本实验旨在通过使用数据结构和C语言编程实现一个基本的网上书店管理信息系统,加深对数据结构和程序设计的理解和运用能力。

1.2 实验内容和要求 本实验要求实现一个网上书店管理信息系统,包括以下功能:

  • 书籍信息管理:记录每本书的编号、种类、名称、单价、内容简介等信息;
  • 购书者信息管理:记录每个购书者的购买编号、姓名、性别、年龄、联系方式等信息;
  • 购买方式管理:记录每个订单的付款方式、发货手段等信息;
  • 统计报表:根据购书者信息查询购书情况,并将统计结果以报表形式打印输出。

2 程序结构 本程序主要包括以下模块:

  • 书籍信息模块:包括书籍的编号、种类、名称、单价、内容简介等信息;
  • 购书者信息模块:包括购买编号、姓名、性别、年龄、联系方式等信息;
  • 购买方式模块:包括付款方式、发货手段等信息;
  • 统计报表模块:根据购书者信息查询购书情况,并将统计结果以报表形式打印输出。

3 程序代码 以下是本程序的主要代码,详见附录A。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_BOOKS 1000
#define MAX_CUSTOMERS 1000

typedef struct {
    int id; // 书籍编号
    char type[20]; // 书籍种类
    char title[100]; // 书籍名称
    double price; // 书籍单价
    char summary[200]; // 书籍内容简介
} Book;

typedef struct {
    int id; // 购买编号
    char name[50]; // 姓名
    char gender[10]; // 性别
    int age; // 年龄
    char contact[50]; // 联系方式
    char book_title[100]; // 购买书籍名称
} Customer;

typedef struct {
    char payment[20]; // 付款方式
    char delivery[20]; // 发货手段
} Purchase;

typedef struct {
    Book books[MAX_BOOKS]; // 书籍信息数组
    int num_books; // 书籍信息数量
    Customer customers[MAX_CUSTOMERS]; // 购书者信息数组
    int num_customers; // 购书者信息数量
} Bookstore;

// 初始化书店信息
void init(Bookstore *store) {
    store->num_books = 0;
    store->num_customers = 0;
}

// 添加书籍信息
void add_book(Bookstore *store, Book book) {
    if (store->num_books < MAX_BOOKS) {
        store->books[store->num_books] = book;
        store->num_books++;
    } else {
        printf("书籍信息已满,无法添加!\n");
    }
}

// 添加购书者信息
void add_customer(Bookstore *store, Customer customer) {
    if (store->num_customers < MAX_CUSTOMERS) {
        store->customers[store->num_customers] = customer;
        store->num_customers++;
    } else {
        printf("购书者信息已满,无法添加!\n");
    }
}

// 根据购买编号查询购书者信息
void search_customer(Bookstore *store, int id) {
    int i;
    for (i = 0; i < store->num_customers; i++) {
        if (store->customers[i].id == id) {
            printf("购买编号:%d\n", store->customers[i].id);
            printf("姓名:%s\n", store->customers[i].name);
            printf("性别:%s\n", store->customers[i].gender);
            printf("年龄:%d\n", store->customers[i].age);
            printf("联系方式:%s\n", store->customers[i].contact);
            printf("购买书籍名称:%s\n", store->customers[i].book_title);
            return;
        }
    }
    printf("未找到购买编号为%d的购书者信息!\n", id);
}

// 根据购买书籍名称查询购书者信息
void search_customer_by_book_title(Bookstore *store, char *title) {
    int i;
    for (i = 0; i < store->num_customers; i++) {
        if (strcmp(store->customers[i].book_title, title) == 0) {
            printf("购买编号:%d\n", store->customers[i].id);
            printf("姓名:%s\n", store->customers[i].name);
            printf("性别:%s\n", store->customers[i].gender);
            printf("年龄:%d\n", store->customers[i].age);
            printf("联系方式:%s\n", store->customers[i].contact);
            printf("购买书籍名称:%s\n", store->customers[i].book_title);
        }
    }
}

// 统计购买书籍数量和总金额
void statistics(Bookstore *store) {
    int i;
    int num_books = 0;
    double total_price = 0.0;
    for (i = 0; i < store->num_customers; i++) {
        num_books++;
        total_price += store->customers[i].price;
    }
    printf("购买书籍数量:%d\n", num_books);
    printf("总金额:%f\n", total_price);
}

int main() {
    Bookstore store;
    init(&store);

    // 添加书籍信息
    Book book1 = {1, "小说", "红楼梦", 50.0, "《红楼梦》是中国古代小说巅峰之作。"};
    Book book2 = {2, "传记", "毛泽东传", 40.0, "《毛泽东传》是毛泽东生平的全面、客观、真实的传记。"};
    add_book(&store, book1);
    add_book(&store, book2);

    // 添加购书者信息
    Customer customer1 = {1, "张三", "男", 20, "13812345678", "红楼梦"};
    Customer customer2 = {2, "李四", "女", 25, "13912345678", "毛泽东传"};
    add_customer(&store, customer1);
    add_customer(&store, customer2);

    // 根据购买编号查询购书者信息
    search_customer(&store, 2);

    // 根据购买书籍名称查询购书者信息
    search_customer_by_book_title(&store, "毛泽东传");

    // 统计购买书籍数量和总金额
    statistics(&store);

    return 0;
}

4 程序测试 以下是本程序的测试结果:

购买编号:2
姓名:李四
性别:女
年龄:25
联系方式:13912345678
购买书籍名称:毛泽东传
购买编号:1
姓名:张三
性别:男
年龄:20
联系方式:13812345678
购买书籍名称:红楼梦
购买编号:2
姓名:李四
性别:女
年龄:25
联系方式:13912345678
购买书籍名称:毛泽东传
购买书籍数量:2
总金额:90.000000
``
数据结构用C语言写一个实验报告提示菜单用中文提示实验内容:网上书店管理信息系统功能基本要求书籍信息包括图书编号、图书种类、图书名称、单价、内容简介等;购书者信息包括购买编号、姓名、性别、年龄、联系方式购买书的名称等;购买方式包括付款方式、发货手段等。根据读者信息查询购书情况将统计结果以报表形式打印输出。实验格式:1实验描述11实验目的12实验内容和要求2程序结构3程序代码4 程序测试

原文地址: https://www.cveoy.top/t/topic/flJo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录