顺序表图书管理系统

//
//  main.c
//  BookMIS
//
//  Created by 李科 on 2023/10/8.
//

#include "main.h"
#include "bookmis.h"
#include

#include "status.h"
#ifndef STATUS_H
#define STAYUS_H

#define OK 1
#define ERROR 0
#define OVERFOLW -2

typedef int Status;

#endif

void PrintBookList(BookList book_list){
    for(int i=0;i

#define MAXSIZE 10000

//图书结构
typedef struct{
    char isbn[100];
    char name[100];
    float price;
} Book;

//基于顺序表的图书列表
typedef struct{
    Book *books;
    int length;
}SqBookList;
typedef SqBookList BookList;

//创建空表
Status InitList(BookList  book_list){
    
    book_list.book=new Book[ MAXSIZE];
    if(book_list.books==NULL){
        exit(OVERFLOW);
    }
    book_list.length=0;
    return OK;
}

//将book插入到第i个元素前面
Status InserBook(BookList book_list,int i,Book book){
    //合法范围1<=i<=length+1
    if(i<1||i>book_list.length+1){
        return ERROR;
    }
    if(book_list.length>=MAXSIZE){
        return ERROR;
    }
    //为新元素腾位置,将原来i个元素以及后面所有元素后移1个单位
    for(int j=book_list.length-1;j>=i-1;j--){
        book_list.book[j+1]=book_list.book[j];
    }
    //插入新元素book
    book_list.book[i-1]=book;
    book_list.length++;
    return OK;
}

//根据序号i获取对应图书Book
Status GetBook(BookList book_list,int i,Book &book){
    //合法范围:1<=i<=length
    if(i<1||i>book_list.length){
        return ERROR;
    }
    book=book_list.books[i-1];
    return OK;
}

#endif

int main(){
    BookList bookList;
    Status status =InitList(bookList);
    if(status==OK){
        for(int i=0;i<3;i++){
            Book book;
            get(book.isbn);
            get(book.name);
            scanf("%d",&book.price);
            InsertBook(bookList,bookList.length+1,book);
        }
        PrintBookList(bookList);
    }
    return 0;
}

你可能感兴趣的:(C语言基础,c#)