【2018.3.17】挣扎的一周

上一周一直在dev、vc6.0、vs2010、vs2017之间挣扎,在我的win10虚拟机里无论哪个都有问题。

dev c++ debug彻底崩了,写c++的时候无法“下一步”;vc6.0 debug文件不存在;vs debug文件已过期。共同的问题是,多文件联编永远通不过编译🙃

终于趁着上机的时候问老师,解决了vc6.0的问题,但是无法单步调试。

vc 6.0的问题是,由于是虚拟机,所以一不留意就会存在着权限不够的问题。之前我使用默认存储路径,没有留意到路径是通到mac的文档里的。后来把路径调成win的C盘就好了。

说起来,我好像知道怎么调vs的问题了。之前照样调路径但是没用,现在想想可能跟安装文件在mac的文档里有关。

重点是,最后寄了点希望在code::blocks上,结果非常好用。至少多文件联编没问题了,debug目前还没试,不过这个问题不大。

放一点纠结的时候码的东西吧:

酒店管理系统:

 

 1 #ifndef hm_h
 2 #define hm_h
 3 #include<cstring>
 4 class person
 5 {
 6 private:
 7     int roomnumber;
 8     char name[10];
 9     char id[19];
10 public:
11     person(int num,char Name[10],char ID[19])    //构造函数,初始化
12     {
13         roomnumber = num;
14         strcpy(name,Name);
15         strcpy(id,ID);
16     }
17     void getinfo(int,char[],char[]);       //定义时数组一定要加[]
18 };
19 
20 class client
21 {
22     float cost;
23     float cost_entertain;
24     float cost_food;
25     float cost_object;
26     float cost_room;
27     int roomnumber;
28     char name[10];
29     char id[19];
30     int timei_d;
31     int timei_m;
32     int timei_y;
33     int timeo_d;
34     int timeo_m;
35     int timeo_y;
36 public:
37     client(int num,char Name[10],char ID[19])
38     {
39         roomnumber = num;
40         strcpy(name,Name);
41         strcpy(id,ID);
42     }
43     void getinfo(int ,char[] ,char[]);
44     void gettimei();
45     void gettimeo();
46     void getcost(int ,int );
47     float calcost();
48     void Delete();
49 };
50 
51 #endif // hm_h
 1 #include<iostream>          //必须将文件名后缀改为”cpp“,否则无法使用头文件
 2 #include"hm.h"
 3 #include<cstring>
 4 using namespace std;
 5 
 6 void person::getinfo(int num,char Name[10],char iden[19])
 7 {
 8     roomnumber = num;
 9     strcpy(name,Name);
10     strcpy(id,iden);
11 }
12 
13 void client::getinfo(int num,char Name[10],char iden[19])
14 {
15     roomnumber = num;
16     strcpy(name,Name);
17     strcpy(id,iden);
18 }
19 
20 void client::gettimei()
21 {
22     int d,m,y;
23     cout << "Please input the check in day:";
24     cin >> d;
25     cout << "Please input the check in month:";
26     cin >> m;
27     cout << "Please input the check in year:";
28     cin >> y;
29     timei_d=d;
30     timei_m=m;
31     timei_y=y;
32 }
33 
34 void client::gettimeo()
35 {
36     int d,m,y;
37     cout << "Please input the check out day:";
38     cin >> d;
39     cout << "Please input the check out month:";
40     cin >> m;
41     cout << "Please input the check out year:";
42     cin >> y;
43     timeo_d=d;
44     timeo_m=m;
45     timeo_y=y;
46 }
47 
48 
49 
50 void client::getcost(int rc_c,int rc_l)
51 {
52     float f,e,o;
53     char catagory;
54     cout << "Please input the food cost:";
55     cin >> f;
56     cout << "Please input the entertain cost:";
57     cin >> e;
58     cout << "Please input the object cost:";
59     cin >> o;
60     cout << "Please input the room class:('c' for common,'l' for luxury)";
61     cin >> catagory;
62     cost_food = f;
63     cost_entertain = e;
64     cost_object = o;
65     while(catagory=='c'||catagory=='l')       //swtich前必须有循环?好像不是诶……那为什么显示我有错误……可能是别的地方的错误吧
66     {
67         switch(catagory)        //无冒号
68         {
69             case'c':cost_room = rc_c*365*(timeo_y-timei_y)+rc_c*30*(timeo_m-timei_m)+(timeo_d-timei_d)*rc_c;break;
70             case'l':cost_room = rc_l*365*(timeo_y-timei_y)+rc_l*30*(timeo_m-timei_m)+(timeo_d-timei_d)*rc_l;break;
71         }
72         break;
73     }
74 }
75 
76 float client::calcost()
77 {
78     cost = cost_food + cost_entertain + cost_object + cost_room;
79     return cost;
80 }
81 
82 void client::Delete()
83 {
84     name[10]={0};
85     id[19]={0};
86 }
87    
  1 #include<iostream>
  2 #include<string>
  3 #include"hm.h"
  4 #include<ctype.h>
  5 using namespace std;
  6 int main()
  7 {
  8     person Person_1(0,"name","1234");     //初始化时字符串数组不能用{0}?
  9     client Client_1(0,"name","1234");
 10     char choice;
 11     int num;
 12     char Name[10];
 13     char iden[19];
 14     cout << "Welcome!\nPlease take down the code of manipulation:\nA.Input one person's information\tB.Check in\tC.Check out"<<endl;
 15     cin >> choice;
 16     choice = toupper(choice);
 17     cout << endl;
 18     while(choice)
 19     {
 20         switch(choice)
 21         {
 22             case('A'):
 23                 {
 24                     cout << "Please input the roomnumber:";
 25                     cin >> num;
 26                     cin.ignore();
 27                     cout << "Please input the name:";
 28                     cin.getline(Name,10);
 29                     cout << "Please input the id:";
 30                     cin.getline(iden,19);
 31                     Person_1.getinfo(num,Name,iden);
 32                     break;
 33                 }
 34             case('B'):
 35                 {
 36                     Client_1.getinfo(num,Name,iden);
 37                     Client_1.gettimei();
 38                     break;
 39                 }
 40             case('C'):
 41                 {
 42                     Client_1.gettimeo();
 43                     int rc_c,rc_l;
 44                     cout << "please input today's common room's cost:";
 45                     cin >> rc_c;
 46                     cout << "Please input today's luxury room's cost:";
 47                     cin >> rc_l;
 48                     Client_1.getcost(rc_c,rc_l);
 49                     cout << "This client's bill will be:\t$"<<Client_1.calcost();
 50                     cout << endl;
 51                     Client_1.Delete();
 52                     break;
 53                 }
 54         }
 55         break;
 56     }
 57     cout << "What would you like to do?(quit or go on?)";
 58     char order[5]={0},quit[5]="quit",go[10]="go on";
 59     cin.getline(order,10);
 60     while(strcmp(order,go)==0)
 61         {
 62             cout << "Please take down the code of manipulation:\nA.Input one person's information\tB.Check in\tC.Check out"<<endl;
 63             cin >> choice;
 64             choice = toupper(choice);
 65             cout << endl;
 66             while(choice)
 67             {
 68                 switch(choice)
 69                 {
 70                     case('A'):
 71                         {
 72                             cout << "Please input the roomnumber:";
 73                             cin >> num;
 74                             cin.ignore();
 75                             cout << "Please input the name:";
 76                             cin.getline(Name,10);
 77                             cin.ignore();
 78                             cout << "Please input the id:";
 79                             cin.getline(iden,19);
 80                             cout << endl;
 81                             Person_1.getinfo(num,Name,iden);
 82                             break;
 83                         }
 84                     case('B'):
 85                         {
 86                             Client_1.getinfo(num,Name,iden);
 87                             Client_1.gettimei();
 88                             break;
 89                         }
 90                     case('C'):
 91                         {
 92                             Client_1.gettimeo();
 93                             int rc_c,rc_l;
 94                             cout << "please input today's common room's cost:";
 95                             cin >> rc_c;
 96                             cout << "Please input today's luxury room's cost:";
 97                             cin >> rc_l;
 98                             Client_1.getcost(rc_c,rc_l);
 99                             cout << "This client's bill will be:\t$"<<Client_1.calcost();
100                             cout << endl;
101                             Client_1.Delete();
102                             break;
103                         }
104                     }
105                 break;
106             }
107             cout << "What would you like to do?(quit or go on?)";
108             cin.ignore();
109             cin.getline(order,10);
110     }
111     if(strcmp(order,quit)==0)
112                 cout << "Thank you!Have a nice day!";
113     return 0;
114 }

明明觉得改了好久的error,但是回头写注释提醒的时候又觉得没什么。

这个程序觉得有点问题,感觉我是为了写题目而写,只能单人单次使用。想在学艺精湛之后结合文件,修改这个小项目。

求出现最频繁的数:

#include<iostream>
using namespace std;
void fre(int *inte, int num);
int main()
{
	int *num, count,i;
	cout << "请问您要求多少个正整数的模?" << endl;
	cin >> count;
	cout << endl;
	num = new int[count];
	cout << "请输入一组正整数:"<<endl;
	for(i=0;i<count;i++)
	{
		cout << "please type:";
		cin >> num[i];
		cout <<endl;
	}
	fre(num, count);
	delete[]num;
	return 0;
}
void fre(int *inte, int num)
{
    int i,j,tem,count=0,number;
    for(i=0;i<num;i++)
    {
        for(j=i+1;j<num;j++)
        {
            if(inte[i]<inte[j])
            {
                tem = inte[i];
                inte[i] = inte[j];
                inte[j] = tem;
            }
        }
    }
    tem=1;
    for(i=1,inte+=1;i<num;inte++,i++)
    {
        if(*inte == *(inte-1))
        {
            tem++;
        }
        else
        {
            if(count < tem)
                {count = tem;
                 number = *(inte-1);
                 tem = 1;
                }
            else if(count == tem)
            {
                count = -1;
            }
        }
    }
	if (count == -1)
		cout << "该组正整数没有最频繁的数!";
	else
		cout << "该组正整数最频繁的数为:" << number;

}

 这个很有问题,测试过程中有的正确,有的错误。错误主要集中在显示 没有最频繁的数(明明有!)可能是我逻辑和数学都不太好吧。先留个坑。

我的第一道文件题

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	fstream datafile;
	char filename[20];
	char context[81];
	cout << "Please type in the file's name:";
	cin.getline(filename, 20);
	cout << endl;
	datafile.open(filename, ios::in);
	if (!datafile)
	{
		cout << "error!";
		exit(0);
	}
	cout << "Having opened the file!"<<endl;
	cout << "Reading the context now!"<<endl;
	while (!datafile.eof())
	{
		datafile.getline(context, 81);
		if (datafile.fail())
			break;
		cout << context << endl;
	}
	datafile.close();
	return 0;

}

 

 

posted @ 2018-03-17 21:38  兔至  阅读(113)  评论(0编辑  收藏  举报