用c++做一个 旅游景点信息管理程序设计

用c++做一个 旅游景点信息管理程序设计,第1张

class CInfo{

struct info

{

int stNo /差谈/编号

string stName //景点名称

string stSpot //旅游地名

float stExpenses//所需费用

}

info stInfo[2]

string spotTemp[2]

void insertInfo(){

cout<<"请输入两个景点编号、名称、地名、所需费用清空。"<<endl

for(int i=0i<3i++){

cout<<"第"<<i <<"个"

cin>>stInfo[i].stNo

cin>>stInfo[i].stName

cin>>stInfo[i].stSpot

cin>>stInfo[i].stExpenses

spotTemp[i] = stInfo[i].stSpot

}

}

void infoShow(){

for(int j=0j<3j++){

cout<<答庆瞎stInfo[j].stNo

cout<<stInfo[j].stName

cout<<stInfo[j].stSpot

cout<<stInfo[j].stExpenses

}

}

void infoQuery(){

string temp

for(int k =0k<3k++){

cout<<"请输入要查询景点地名: "

cin>>temp

if(temp != spotTemp[k]){

cout<<"没有查询到你想要的信息!"<<endl

}else{

cout<<stInfo[k].stSpot

}

}

}

}

#include<iostream>

#include<string>

#include<conio.h>

#include<fstream>

#define filepath "JDInfo.txt"

#define max 1000

using namespace std

typedef struct JDInfo

{

    string jdid

    string jdname

    string cityname

    float money

}JDInfo

static int count

static JDInfo jdinfo[max]

int load_info()

{

    count = 0

    ifstream ifs(filepath, ios::in)

    if(ifs.good())

    {

        

        while(!ifs.eof())

        {

            ifs >> jdinfo[count].jdid

            ifs >> jdinfo[count].jdname

            ifs >> jdinfo[count].cityname

            ifs >> jdinfo[count++].money            

        }

        ifs.close()

        return count

    } 

    else

        return 0 

}

bool write_info()

{

    cout << "请输入景点编号:"

    cin >> jdinfo[count].jdid

    cout << "\n请输入景点名称:"

    cin >敬老> jdinfo[count].jdname

    cout << "\n请输入旅游地名称:"

    cin >> jdinfo[count].cityname

    cout << "\n请输入所需费用:"

    cin >> jdinfo[count].money

    ofstream ofs(filepath, ios::app)

    if(ofs.good())

    {

        ofs << jdinfo[count].jdid << endl

        ofs << jdinfo[count].jdname << endl

        ofs << jdinfo[count].cityname << endl

        ofs << jdinfo[count++].money << endl

        cout << "输入记录成功!请按任意键继续..." << endl

        getch()

        ofs.close()

        return true

    }

    else

        return false    

}

void read_info()

{

    int i = 0

    system("cls")

    for(  i < count i++)

    {

        cout << "第" << i + 1 << "个景点数据:" << endl

        cout << "景点编号:" << jdinfo[i].jdid << endl

        cout << "景点名称:" << jdinfo[i].jdname << endl

        cout << "旅游地名称:" << jdinfo[i].cityname << endl

        cout << "所需费用:" << jdinfo[i].money << endl

    }

    system("pause")

}

float calc_money(string n)

{

    float smoney = 0.0

    int i = 0

    for(  i < count i++)

    {

        if(jdinfo[i].cityname == n)

            smoney += jdinfo[i].money

    }

    return smoney

}

int main()

{

    load_info()

    string tempname

    while(true)

    {

        cout << "请选择所需功能:" << endl

        cout << "局源1.输入数据" << endl

        cout << "2.显示所有信息" << endl

        cout << "3.输入旅游地查询并计算总所需费用" << endl

        cout << "4.退出系统" << endl

i:      switch(getch())

        {

            case '1': write_info() break

      亮腊升      case '2': read_info() break

            case '3':

                    cout << "请输入旅游地名称:"

                    cin >> tempname

                    cout << "\r去 " << tempname << " 旅游,所需要总费用为:" << calc_money(tempname) << endl 

                    break

            case '4': return 0 break

            default: cout << "\r输入选择错误,请重新输入:"goto i

        }

    }

}

给你写了一个,你去运行看下,有什么不懂的再问我吧。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12360812.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存