64,676
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <iomanip>
using namespace std;
class book
{
public:
book () {}
book(int t,int b)
{
type = t;bno = b;
}
int type;//类型
int bno;//编号
};
class lbook:public book
{
public:
lbook () {}
lbook(int t,int b,int s):book(t,b)
{
storage = s;
}
void set(int t,int b,int s)
{
storage = s;
}
int storage;
};
class pbook :public book
{
public:
pbook () {}
pbook(int t,int b,double p):book(t,b)
{
price = p;
}
void set(int t,int b,double p)
{
price = p;
}
double price;
};
int main()
{
int storge_total = 0;
double price_total = 0;
int count_pbook = 0;
int l = 0,p = 0;
book* lb[10000],* pb[1000];
int type,bno;
double st_pri;
cin >> bno >> type >> st_pri;
while(cin)
{
if (type == 0)
{
pb[p] = new pbook(type,bno,st_pri);
count_pbook ++;
price_total += st_pri;
p++;
}
if (type == 1)
{
lb[l] = new lbook(type,bno,st_pri);
storge_total += st_pri;
l++;
}
cin >> bno >> type >> st_pri;
}
for (int j = 0;j <= l;j++)
{
if (lb[j] -> type == 1)//文学
cout << lb[j] -> bno << " " << lb[j] -> type << " " << ((lbook*)lb[j]) -> storage << endl;
else continue;
}
for (int t = 0;t <= p;t++)
{
if (pb[t] -> type == 0)//理学
cout << pb[t] -> bno << " " << pb[t] -> type << " " << ((pbook*)pb[t]) -> price << endl;
else continue;
}
cout << storge_total << endl;
cout.setf(ios::fixed);
cout << setprecision(1);
cout << price_total / count_pbook << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
class book
{
public:
book () {}
book(int t,int b)
{
type = t;bno = b;
}
int type;//类型
int bno;//编号
};
class lbook:public book
{
public:
lbook () {}
lbook(int t,int b,int s):book(t,b)
{
storage = s;
}
void set(int t,int b,int s)
{
storage = s;
}
int storage;
};
class pbook :public book
{
public:
pbook () {}
pbook(int t,int b,double p):book(t,b)
{
price = p;
}
void set(int t,int b,double p)
{
price = p;
}
double price;
};
int main()
{
int storge_total = 0;
double price_total = 0;
int count_pbook = 0;
int l = 0,p = 0;
book* lb[10000],* pb[1000];
int type,bno;
double st_pri;
cin >> bno >> type >> st_pri;
while(cin)
{
if (type == 0)
{
pb[p] = new pbook(type,bno,st_pri);
count_pbook ++;
price_total += st_pri;
p++;
}
if (type == 1)
{
lb[l] = new lbook(type,bno,st_pri);
storge_total += st_pri;
l++;
}
cin >> bno >> type >> st_pri;
}
for (int j = 0;j < l;j++)
{
if (lb[j] -> type == 1)//文学
cout << lb[j] -> bno << " " << lb[j] -> type << " " << ((lbook*)lb[j]) -> storage << endl;
else continue;
}
for (int t = 0;t < p;t++)
{
if (pb[t] -> type == 0)//理学
cout << pb[t] -> bno << " " << pb[t] -> type << " " << ((pbook*)pb[t]) -> price << endl;
else continue;
}
cout << storge_total << endl;
cout.setf(ios::fixed);
cout << setprecision(1);
cout << price_total / count_pbook << endl;
return 0;
}
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。
提醒:再牛×的老师也无法代替学生自己领悟和上厕所!
单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。