c++基础项目,车辆租赁管理系统,设计与实现.程序设计基础作业,C语言课程设计作业

内含文件流操作

需要把文件创建在根源代码一个文件目录下

文件名是carxinxi.txt 

eve.txt 

 mima.txt

#include<iostream>
#include<cstdio>
#include<cstring>
#include<windows.h>
#include<fstream>
#include<time.h> 
 
using namespace std;
 
void welcome();
void chushihua();
void denglu();
void xiugaimima(); 
void show();
void carData ();
void back();
int carshumu();
void cartianjia();
void shanchucar();
void npc(); 
const string currentDateTime();
void jiaona();
int days(int x,int y,int z);
int nianshu(int n);
void jishiqi();
int chazhao(); 

struct xinxi
{
    char plate_num[20];
    char brand[20];
    char model[20];
    float capacity;
    char colour[20];
    double rate_per_day;
    char date[20];
    
};

    xinxi rent[1000];//车辆结构体数组 
    
int main ()
{
    //主程序 (以下) 
    chushihua();//进入页面logo
    denglu(); //登录 
    
    welcome();//核心程序
    
}
 
void denglu()
    {
        string a,c; 
        
        ifstream ifs;
        ifs.open("mima.txt",ios::in);//读取密码 
        ifs>>c;    
        ifs.close();
         
        cout<<"\n  ******\t\t\t\t  请登录...    ";
        Sleep(2000);
        system("cls");
        
        cout<<"\t\t\t*******************************************" <<endl; 
        cout<< "\n  ******\t\t\t\t | 请输入密码:";
        cin>>a;
        if (a==c)
        {
            cout<<"***           登录成功..."; 
            Sleep(1000);
            system("cls");
        } 
        else
        {
            cout<<"***        密码错误,请重新登录";
            Sleep(1000);
            system("cls");
            
            denglu(); 
        } 
    }

void chushihua()
    {
        ifstream ifs;
        ifs.open("eve.txt",ios::in);
        char buf[2000]={0};
        
        string Lines = "";
        
        if (ifs)
        {
            while (ifs.good ())
            {
                string TempLine;
                getline (ifs , TempLine);
                TempLine += "\n";
            
                Lines += TempLine;
            }
            
        cout << Lines;
        }
        ifs.close();
        
        Sleep(2000);
        system("cls");
    }

int days(int x,int y,int z)  //x:年 y:月 z:日 
{
    int i,j=0,k;    
                //计时器子程序 
    for(i=1;i<=y-1;i++)
    {
        switch(i)
        {
            case 1:case 3:case 5:case 7:case 8:case 10:case 12:k=31;break;
            case 4:case 6:case 9:case 11:k=30;break;
            case 2:
            {     
                    if((x%100!=0&&x%4==0)||(x%100==0&&x%400==0))
                        k=29;
                    else 
                        k=28;
            }
            
            break;
        }
        j+=k;        
    }
    j+=z;
    
    return j;
}
int nianshu(int n)
{                //计时器子程序2 
    int m=0;
    if((n%100!=0&&n%4==0)||(n%100==0&&n%400==0))
    { 
        m=366;
    } 
    else 
    {    
        m=365;
        } 
    return m;
    

void jishiqi()//计时器 
{
    int a,b,c,d,e,f,s=0,t,j;
    
    printf("\n\t请输入起租与还车日期(年 月 日 以空格隔开,两个日期也以空格隔开):\n");
    cout<<"\t";
    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
    //两个日期算出共用的天数 
    s=s-days(a,b,c);
    
    for(t=a;t<d-1;t++)
    {
        s+=nianshu(t);    
    }
    
    s=s+days(d,e,f);
    j=chazhao(); //查找出租用该车的日租金 
    printf("累计租车%d天\n",s);    
    
    cout<<endl<<"应缴纳租金:"<<j*s<<"元" ; 
}
int chazhao()
    {    
    char plate[10];
    int car2; 
    
    ifstream ifs;
    ifs.open("carxinxi.txt");
    cout << "\n\t  | \t\t输入车牌号(大写字母): "<<endl;
    cout<< "\t  |  \t\t\t\t\t\t\t";
    cin >> ws;
    cin.getline(plate,10);
    
    int x=carshumu();
    for(int i = 0; i < carshumu(); i++)
    {
        if (strcmp(plate,rent[i].plate_num) == 0)
        {
            car2= rent[i].rate_per_day;
            ifs.close();
            return car2; 
        }
    }
    
    ifs.close();
    
    cout<<"车牌号输入有误,请重新输入" ;
    chazhao(); 
    
    } 
    
void xiugaimima()
{
    string a;
     
    cout<<"         请输入新密码 (不含空格) :";
    cin>>a;
    ofstream ofs;
    ofs.open("mima.txt",ios::trunc);
    ofs<<a; 
    ofs.close(); 
    
    system("cls");
    cout<<"          修改成功..."; 
    Sleep(1000);
    system("cls");

int carshumu()
{
    int car0 = 0;
    ifstream ifs("carxinxi.txt"); 

    string wa;
    while (getline(ifs, wa))
    {
        if (!wa.empty())
            car0++;
    }
    
    ifs.close();

    return car0;
}

void carData ()
{
    ifstream ifs;
    ifs.open("carxinxi.txt");
    int carNum = 0;
    
    while(!ifs.eof())
    {
        ifs.getline(rent[carNum].plate_num,20,' ');
        ifs.getline(rent[carNum].brand,20,' ');
        ifs.getline(rent[carNum].model,20,' ');
        
        ifs >> rent[carNum].capacity;
        ifs.ignore();
        ifs.getline(rent[carNum].colour,20,' ');
        
        ifs.getline(rent[carNum].date,20,' ');
        ifs >> rent[carNum].rate_per_day;
        ifs.ignore();
        
        carNum++;
        ifs>>ws;
    }
    
    ifs.close();
}

void show()
{
    cout<<"\n\n";
    cout << endl;
    carData ();
    
    cout << "\t  |  车牌号\t品牌\t 型号\t排量\t    颜色 \t    每天租金\t  租车日期\t" << endl;
    cout << "\t  |  =======================================================================================================================" << endl;
    for (int i = 0; i < carshumu(); i++)
    {
        cout << "\t  |  " << rent[i].plate_num << "\t" << rent[i].brand << "\t " << rent[i].model << "\t " << rent[i].capacity << "\t  "
             << rent[i].colour << "\t\t  " << rent[i].rate_per_day 
             << "\t\t "<< rent[i].date<<"\t"<<endl;
    }
    cout << "\n\n";
}

void back(){
    int  back0; 
    cout<<"输入1返回主菜单:";
    cin>>back0; 
    if(back0==1)
    {    system("cls");
        welcome();
     } 
     else back();
}

void newCarData()
{
    ofstream ofs;
    ofs.open("carxinxi.txt" , fstream::app);
    ofs<<endl;
    
    int newCar = carshumu() + 1;
    cout << "\n\n";
    cout << "\n\t  |\t\t\t\t\t  请输入一下数据: "<< endl;
    
    cout << "\n\t  |\t\t\t\t\t 车牌号 : ";
    cin >> ws;
    cin.getline(rent[newCar].plate_num,10);
    ofs << rent[newCar].plate_num;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  品牌 : ";
    cin.getline(rent[newCar].brand,20);
    ofs << rent[newCar].brand;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  型号 : ";
    cin.getline(rent[newCar].model,20);
    ofs << rent[newCar].model;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  排量 : ";
    cin >> rent[newCar].capacity;
    ofs << rent[newCar].capacity;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  颜色 : ";
    cin >> ws;
    cin.getline(rent[newCar].colour,20);
    ofs << rent[newCar].colour;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  租车日期 : ";
    cin >> rent[newCar].date;
    ofs << rent[newCar].date;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  每天的租金: ";
    cin >> rent[newCar].rate_per_day;
    ofs << rent[newCar].rate_per_day;
    ofs << " ";
    
    ofs.close();
    
    cout<<"  "<<endl<<"          添加成功..."; 
    Sleep(1000);
    system("cls");
    carData();
    welcome();
}

void shanchucar()
{
    char plate[10];
    
    ofstream ofs;
    ofs.open("temp.txt");
    
    show();
    
    cout << "\n\n";
    cout << "\t  | \t\t输入要删除的车牌号(大写字母): "<<endl;
    cout<< "\t  |  \t\t\t\t\t\t\t";
    cin >> ws;
    cin.getline(plate,10);
    
    int x=carshumu();
    for(int i = 0; i < carshumu(); i++)
    {
        if (strcmp(plate,rent[i].plate_num) != 0)
        {
            ofs << rent[i].plate_num;
            ofs << " ";
            ofs << rent[i].brand;
            ofs << " ";
            ofs << rent[i].model;
            ofs << " ";
            ofs << rent[i].capacity;
            ofs << " ";
            ofs << rent[i].colour;
            ofs << " ";
            ofs << rent[i].date;
            ofs << " ";
            ofs << rent[i].rate_per_day;
            ofs << " ";
            if(i != carshumu())
            {
                ofs<<endl;
            }    
        }
    }
    ofs.close();
    
    remove("carxinxi.txt");
    rename("temp.txt","carxinxi.txt");
    
    
    system("cls");
    
    cout<<"        "<<endl<<"          已删除车辆信息..."; 
    Sleep(1000);
    system("cls");
    
    carData();
    welcome();
}

void npc()
    {
        cout<<endl;
    cout<<"\n\t  |\t\t\t1.  最低租金时间是7天";
    cout<<"\n\t  |\t\t\t2.  所有车辆已缴纳保险";
    cout<<"\n\t  |\t\t\t3.  万一发生意外,所有费用由司机支付";
    cout<<"\n\t  |\t\t\t4.  准备身份证明物品";
    cout<<"\n\t  |\t\t\t5.  如果迟到的话,额外的费用";
    cout<<"\n\t  |\t\t\t6.  安全驾驶!";
    cout<<"\n\n\n\n\t  |\t\t\t                           按任意键继续  :)";
    cout<<"\n\t  |\t\t\t                                                            ";
    //租车说明或者系统说明可自己更改 
    getchar();getchar();
    
    back();    
    }
    
const string currentDateTime() //获取系统时间,方便缴纳租金时填写还车日期 
    {
        time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%d/%m/%Y 时间: %X", &tstruct);

    return buf;
    }    
    
void jiaona()
    {
        show();
        cout<<"\t"<<"当前时间 日期:"<<currentDateTime();
        jishiqi();
        cout<<"\n\t"; 
        
        back(); 
    }    
    
void welcome()
{
    int x;
     
    cout<<"\n  **\t\t\t\t\t\t\t  1. <农业车辆信息>";
    cout<<"\n  **\t\t\t\t\t\t\t  2. <添加车辆>";
    cout<<"\n  **\t\t\t\t\t\t\t  3. <删除车辆>";
    cout<<"\n  **\t\t\t\t\t\t\t  4. <修改密码>";
    cout<<"\n  **\t\t\t\t\t\t\t  5. <系统说明>";
    cout<<"\n  **\t\t\t\t\t\t\t  6. <缴纳租金>";
    cout<<"\n  **\t\t\t\t\t\t\t  7. <退出>"<<endl<<"\n";
    cout<<"\n  **\t\t\t\t\t\t\t  INPUT :";

    cin>>x;
    
    if (x == 7)//退出
        {
            cout << "退出系统,欢迎下次使用" << endl;
            system("pause");
            return ;
        }
    else if(x==1)
        {
            system("cls");
            show();
            back(); 
         } 
    else if (x==2)
        {    
            system("cls");
            newCarData();
        }
    else if(x==3)
        {
            system("cls");
            shanchucar();    
         } 
    else if(x==4)
        {    
            system("cls");
            xiugaimima(); 
            welcome();
         } 
    else if(x==5)
        {
            system("cls");
            npc();    
        }
    else if(x==6)     
        {
            system("cls");
            jiaona();        
        } 
     
}

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
一个简单的汽车租赁管理系统C++控制台程序): 利用C++实现对汽车和客户信息的增、删、改等操作,并保存。 部分代码: // CarRent.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "CarData.h" #include "Menu.h" #include"CustomerData.h" int main() { Menu::welcome(); Menu::login(); //登录界面 char choice; int carid, customerid; //汽车编号,客户编号 CustomerData CustomerDB; //客户库 Customer *r; //客户 CarData CarDB; //汽车库 Car *b; //汽车 Menu::showMenu(); //显示菜单 cout <> choice; while (choice != '0') { switch (choice) { case '1': //输入客户编号和要出租的汽车 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); if (NULL == r) { cout << "不存在该客户!"; cout << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!"; cout <borrowCar() == 0) { cout << "该汽车已租出!"; cout <borrowCar(b->getNo()); cout << "你在" <getBorTime()) << "成功出租一辆" <getName() << endl << "每日租金为(不足一天按一天计算):" <getPay(); break; case '2': //归还操作 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); //按编号查找 if (r == NULL) { cout << "不存在该客户!" << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!" <getOnshelf() == 1) { cout << "该汽车已经归还!" << endl; break; } cout << "您成功归还一辆"
很高兴为您解答问题。您的问题是关于C++图书管理系统的,那么我将为您提供一种基于数组实现的C语言课程设计方案。 首先,我们可以定义一个结构体来表示每一本书的信息,包括书名、作者、出版社、出版日期、价格等等。例如: ``` struct Book { char name[50]; char author[50]; char publisher[50]; char date[20]; float price; }; ``` 然后,我们可以定义一个数组来存储所有的书籍信息,例如: ``` Book books[100]; ``` 接下来,我们可以实现一些基本的功能,如添加书籍、删除书籍、查询书籍等等。下面是一个简单的添加书籍的函数实现: ``` void addBook() { Book book; printf("请输入书籍信息:\n"); printf("书名:"); scanf("%s", book.name); printf("作者:"); scanf("%s", book.author); printf("出版社:"); scanf("%s", book.publisher); printf("出版日期:"); scanf("%s", book.date); printf("价格:"); scanf("%f", &book.price); // 将新书籍加入数组 books[num] = book; num ++; printf("添加成功!\n"); } ``` 其中,num表示当前已经有多少本书籍被添加进来了。 除了添加书籍外,我们还可以实现删除书籍的功能,例如: ``` void deleteBook() { char name[50]; printf("请输入要删除的书籍的书名:"); scanf("%s", name); int flag = 0; for (int i = 0; i < num; i++) { if (strcmp(books[i].name, name) == 0) { // 找到了要删除的书籍,将其移出数组 for (int j = i; j < num - 1; j++) { books[j] = books[j+1]; } num --; flag = 1; printf("删除成功!\n"); break; } } if (!flag) { printf("未找到该书籍!\n"); } } ``` 最后,我们可以编写一个主函数,提供一个简单的菜单供用户选择不同的功能,例如: ``` int main() { while (1) { printf("请选择功能:\n"); printf("1.添加书籍\n"); printf("2.删除书籍\n"); printf("3.查询书籍\n"); printf("4.退出系统\n"); int choice; scanf("%d", &choice); switch (choice) { case 1: addBook(); break; case 2: deleteBook(); break; case 3: searchBook(); break; case 4: return 0; default: printf("输入有误,请重新输入!\n"); } } return 0; } ``` 以上是一个简单的C语言课程设计方案,基于数组实现的图书管理系统。希望能对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值