程序设计问题急救

程序设计问题急救,第1张

#include <iostream>  

#include <cstdio>  

#include <algorithm>  

#include <cstring>  

#include <queue>  

#include <set>  

#include <map>  

#include <timeh>  

using namespace std;  

  

int sale[1000][6] = {0};    //分别表示每个优惠中每个商品数量   

int saleprice[1000] = {0};  //优惠总价   

int salelength[1000] = {0}; //优惠总共有几个商品   

int salenumber[1000][1000] = {0};   //优惠商品的ID   

int good[6][4] = {0};       //1 -> number   2 -> price  3 -> last num  

int num[1000];              //商品ID   

int dp[6][6][6][6][6];    

int n,m;  

  

void input()  

{  

        cin>>n;  

        for(int i = 1; i  <= n; i++)  

        {  

            cin>>good[i][1]>>good[i][3]>>good[i][2];  

            num[i] = good[i][1];  

        }  

        cin>>m;  

        for(int i = 1; i <= m; i++)  

        {  

                cin>>salelength[i];  

                for(int j = 1; j <= salelength[i]; j++)  

                {  

                        cin>>salenumber[i][j];  

                        cin>>sale[i][salenumber[i][j]];  

                }  

                cin>>saleprice[i];  

        }  

}  

  

void output()  

{  

    for(int i = 1; i  <= n; i++)  

        cout<<"goodnum: "<<good[i][1]<<" goodprice: "<<good[i][2]<<" goodlast: "<<good[i][3]<<endl;  

    for(int i = 1; i  <= m; i++)  

    {  

        //cout<<salelength[i]<<endl;  

        cout<<"sale"<<i<<" : ";  

        for(int j = 1; j <= salelength[i]; j++)  

                cout<<"num: "<<salenumber[i][j]<<" count: "<<sale[i][salenumber[i][j]]<<" ";  

        cout<<endl;  

       cout<<" price: "<<saleprice[i]<<endl;  

  

    }  

}  

int main()  

{  

    //freopen("in2","r",stdin);  

    input();  

   // output();  

    dp[0][0][0][0][0] = 0;  

      for(int i = 0; i <= good[1][3]; i++)  

            for(int j= 0; j <= good[2][3]; j++)  

                    for(int k = 0; k <= good[3][3] ;k++)  

                            for(int l = 0; l <= good[4][3]; l++)  

                                    for(int p = 0; p <= good[5][3]; p++)  

{  

int minx = i  good[1][2] + j  good[2][2] + k  good[3][2]  

 + l  good[4][2] + p  good[5][2];  

    for(int q = 1; q <= m; q++)  

    {  

        if(i -sale[q][num[1]]<0 || i - sale[q][num[2]]<0 ||   i-sale[q][num[3]]<0 || i-sale[q][num[4]]<0 ||i-sale[q][num[5]]<0)          continue;  

        int t = dp[i - sale[q][num[1]]][j - sale[q][num[2]]][k - sale[q][num[3]]][l - sale[q][num[4]]][p - sale[q][num[5]]] + saleprice[q];  

  

       if(t < minx) minx = t;  

    }  

  

       dp[i][j][k][l][p] = minx;  

}  

                        cout<<dp[good[1][3]][good[2][3]][good[3][3]][good[4][3]][good[5][3]]<<endl;  

return 0;  

}

编制一个航班订票系统。应具备如下功能:该航班仅有一架100座飞机;该飞机座位分为吸烟区(30个座位)和无烟区(70个);订票系统界面是选择菜单:1选吸烟区座位号;2选无烟区座位号;用户输入自己的选择后,该区若有空位,则顺序地分配一个座号;否则致歉;若吸烟区已满而无烟区有空位,则征求顾客意见,是否愿意得到无烟区的空位,若愿意,则在无烟区分配一个座号,否则致歉退出;顾客不得自主挑选座位号;

#include<cstdio>

#include<stdlibh>

#include<stringh>

#include<memoryh>

#define LIN 31

#define LIE 71

static int smok[LIN];//吸烟区票

static int nosmoke[LIE];//无烟区票

void Initnosmoke();//初始化

void ASK();void Initsmok();

void nosmok();

void smoke();

int search(int array,int size);

void show();

int main()

{

Initnosmoke();

Initsmok();show();return 0;}void Initnosmoke()//初始化无烟区票{int sun=0;for(int j=0;j<LIE;j++){sun+=1;nosmoke[j]=sun;}}void Initsmok()//初始化吸烟区票{int k=0;for(int i=0;i<LIN;i++){k+=1;smok[i]=k;}}int search(int array,int size)/该函数的作用是用来查看系统中某类票是否卖完,入股卖完了返回1,反之返回的是0/{int i;for(i=0;i<size;i++){if(array[i]!=0){return 0;}else{;}}return 1;}void nosmok()//购买无烟区票{for(int i=0;i<LIE;i++){if(i<LIE-1){if(nosmoke[i]!=0){printf("你票是:NOSMOKE_%d\n",nosmoke[i]);nosmoke[i]=0;break;}else{;}}else{printf("对不起!NOSMOKE票已售完!");}}}void ASK()/该函数用来询问客户是否需要买NOSMOKE票当SMOKE票卖完的情况下/{char ask;printf("NOSMOKE票你要吗(y/n)\n");ask=getchar();if(ask =='y' || ask=='Y' ){nosmok();}else if(ask=='n' || ask=='N'){printf("谢谢!再见\n");}else{printf("输入错误!\n");}}void smoke()//购买吸烟区票{for(int j=0;j<LIN;j++){if(j<LIN-1){if(smok[j]!=0){printf("你票是: SMOKE_%d\n",smok[j]);smok[j]=0;break;}else{;}}else{printf("对不起!SMOKE票已售完!");{fflush(stdin);int rec=search(nosmoke,LIE);if(rec==0){ASK();}else{printf("谢谢!\n");}}}}}void window(){printf("\t\t欢迎使用航班订票系统\n");printf("\t\t1吸烟区座位\n");printf("\t\t2无烟区座位\n");printf("\t\t3退出系统\n");printf("\t\t请选择(1~3)进行 *** 作:\n");}void show(){system("color 4a");char ch=' ';window();while(ch!='3'){fflush(stdin);ch=getchar();switch(ch){case '1':{smoke();break;}case '2':{nosmok();break;}case '3':{break;}default:break;}window();ch=getchar();}}

我修改了下,下面的代码在Windows XP + VC++60下正常运行,直接复制粘贴就行了

有2点是你需要注意的

(1)题目的意思是:

"当输入:"后面的那句"How about you"和"输入:"后的那句"OK"是由你从键盘中输入的,其它的都由程序自动输出

(2)你存在很多语法错误

比如C++中是分大小写的,可你的代码中大小写不分;

类成员函数的定义格式也不对

建议你先看一下C++基础教材,先掌握语法,模仿教材上的设计

#include<iostream>

#include<cstdio>//函数strcpy(),stcmy()包含在此头文件中

using namespace std;

class Welcome

{

private:

char str[128];

public:

Welcome(char s[]="Welcome!");

Welcome (Welcome &);

void set(char []);

void display();

char Get();

void talk();

~Welcome();

};

Welcome::Welcome(char s[])//默认参数值在函数声明中已写了,此处若改为char s[]="Welcom!"错

{

strcpy(str,s);//把字符串数组s中的所有字符,拷贝到字符串数组str中

}

Welcome::Welcome(Welcome &c)//拷贝构造函数

{

strcpy(str,cstr);

}

void Welcome::set(char s[])

{

strcpy(str,s);

}

void Welcome::display()

{

cout<<str<<endl;

}

char Welcome::Get()

{

return str;

}

Welcome::~Welcome()

{

cout<<"Goodbye!"<<endl;

}

void Welcome::talk()

{

char s[128];

cout<<"当输入:";

cingetline(s,128);//不用cin>>s;因为输入为几个字符串

while(strcmp(s,"OK")!=0)//s不等于"OK"时,循环输出及输出

{

cout<<"就输出:"<<s<<endl;

cout<<"输入:";

cingetline(s,128);

}

strcpy(str,"OK");//或strcpy(str,s);因为执行到这个指令时,必有s="OK"

cout<<"All right!"<<endl;

cout<<"Goodbye!"<<endl;

}

void main()

{

Welcome we;

Welcome you(we);

youdisplay();

youset("Thank you");

cout<<youGet()<<endl;

youtalk();

youdisplay();

}

/运行结果

Welcome!

Thank you

当输入:How about you

就输出:How about you

输入:OK

All right!

Goodbye!

OK

Goodbye!

Goodbye!

Press any key to continue

/

1、打开matlab,在命令行窗口中输入a=[12 24 35;26 78 56],创建一个2行3列的矩阵

2、在命令行窗口中输入mean(a(:)),求a矩阵所有元素的平均值。

3、按回车键之后,可以看到a矩阵所有元素的平均值是 385000。

4、如果想求矩阵每一列的平均值,输入mean(a,1)。

5、如果想求矩阵每一行的平均值,输入mean(a,2)。

注意事项:

C语言能以简易的方式编译、处理低级存储器。C语言是仅产生少量的机器语言以及不需要任何运行环境支持便能运行的高效率程序设计语言。

以上就是关于程序设计问题 急救全部的内容,包括:程序设计问题 急救、C语言程序设计 飞机订票管理系统、<<C++语言程序设计>>中的第一题,我编了以下程序,可老出错,想请各位大侠帮帮忙!先谢谢了!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: http://outofmemory.cn/zz/9667270.html

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

发表评论

登录后才能评论

评论列表(0条)

保存