学习C++第六天

今天是第六天,学习内容如下:
1.do while 语句;
2.for循环语句:for(初始语句;表达式1;表达式2){循环体};
先执行初始语句,再判断表达式1,表达式1值为true时执行循环体,循环体执行完毕执行表达式2;
3.循环结构与选择结构的嵌套;
4.break语句,跳出最近一层循环体或switch;
5.continue语句,continue之后的循环体不执行,直接判断是否执行下一次循环;
6.go to 语句,跳转到指定语句;
7.类型别名,为已有类型另外命名,增加可读性;
typedef 已有类型名 新类型名表;如typedef double area;
using 新类型名=已有类型名;如using area = double;
8.新类型定义:
枚举类型:将该类型所有可取到的值全部枚举出;
enmu 枚举类型名 {变量值列表};
如:enmu weekday {sun,mon,tue,wed,thu,fri,sat};
默认情况下sun=0,mon=1,…,sat=6;
可在定义时指定枚举元素的值,定以后不可更改枚举元素的值;
如:enmu weekday{sun=7,mon=1,tue,wed,thu,fri,sat};
此时tue=2;
枚举值可赋值给整形变量,整形变量赋值给枚举型时要进行强制类型转换。
9.auto类型,如auto val=val1+val2;val的类型为val1+val2的类型;
10.decltype类型,decltype(i) j=2;j值为2,类型与i相同;
11.函数
函数是定义好的功能模块
函数语法形式:
类型标识符 函数名 (形式参数表)
{
语句序列;
}
函数调用形式:函数名 (实参列表)
12.嵌套调用:一个函数中会调用其他函数;(只学了概念)
13.递归调用:函数自身会调用自身;(只学了概念)
14.今日代码:
#include
using namespace std;

double power(double x, int n)
{
double val = 1;
while (n–)
val *= x;
return val;
}

int main()
{
double pow;
pow = power(5, 2);
cout << "5 to the power 2 is " << pow << endl;
return 0;
}

#include
using namespace std;

struct mytime
{
unsigned int year;
unsigned int month;
unsigned int day;

unsigned int hour;
unsigned int min;
unsigned int sec;

};

int main()
{
mytime mytime = { 2015,3,16,12,0,0 };
do {
cout << “输入年” << endl;
cin >> mytime.year; } while (mytime.year > 9999);
do {
cout << “输入月” << endl;
cin >> mytime.month; } while (mytime.month > 12);
do {
cout << “输入日” << endl;
cin >> mytime.day; } while (mytime.day > 31);
do {
cout << “输入时” << endl;
cin >> mytime.hour; } while (mytime.hour > 24);
do {
cout << “输入分” << endl;
cin >> mytime.min; } while (mytime.min > 60);
do {
cout << “输入秒” << endl;
cin >> mytime.sec; } while (mytime.sec > 60);

cout << "the time is set to" << mytime.year << "/" << mytime.month << "/" << mytime.day << " " << mytime.hour << ":" << mytime.min << ":" << mytime.sec << endl;

}

#include
using namespace std;
int main()
{
int itype;
float radius, a, b, area;

cout << "please enter the type of this graph,1-圆形,2-长方形,3-正方形" << endl;
cin >> itype;
switch (itype)
{
case 1:cout << "please enter the radius";
	cin >> radius;
	cout << "○面积是"<<3.14 * radius*radius<<endl;
	break;
case 2:cout << "请输入长和宽" << endl;
	cin >> a;cin>> b;
	cout << "长方形面积是" << a * b << endl;
	break;
case 3:cout << "请输入边长" << endl;
	cin >> a;
	cout << "正方形面积是" << a * a<<endl;
	break;
}
return 0;

}

#include
using namespace std;
enum Gameresult{ WIN,LOSE,TUE,CANCEL };
int main()
{
Gameresult result;
enum Gameresult omit = CANCEL;//两种定义方法均可。
for (int count = WIN; count <= CANCEL; count++)
{
result = Gameresult(count);
if (result == omit)
cout << “the game was canceled” << endl;
else
{
cout << “the game was played”;
if (result == WIN) cout << “and we won!”;
if (result == LOSE) cout << “and we lose”;
cout << endl;
}
}
return 0;
}

今天把选课的事弄完了,这周一直纠结这个,终于在今天弄完了,上午下午晚上都学了C++,感觉进度有点慢,明天要把现代CAD的作业做了,国庆之前C++视频要看完,感觉有点赶,之前听旺哥说读研轻松得很,我这读起来感觉吃力得很,有些课老师默认你会Python,计算机基础知识,我听起来好多不懂,有些是英文授课,更不懂,有些讲座性质的课我最喜欢,可惜不多,下周一又要上现代CAD了,不知道又有什么新作业,明天还要提交课题组周报,也不知道写什么,就写下自己写的C++知识好了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值