7.5课堂笔记
1.字符长度
Char-----1字符
Short-----2字符
Int-----4字符
Long int-----4字符
Long long-----8字符
Float-----4字符
Double-----8字符
Long double-----12字符
Bool-----1字符
Void
#include<iostream>
using namespace std;
int main()
{
cout << "char size" << sizeof(char) << endl;
cout << "short size" << sizeof(short) << endl;
cout << "int size" << sizeof(int) << endl;
cout << "long int size" << sizeof(long int) << endl;
cout << "long long size" << sizeof(long long) << endl;
cout << "float size" << sizeof(float) << endl;
cout << "double size" << sizeof(double) << endl;
cout << "long double size" << sizeof(long double) << endl;
cout << "bool size" << sizeof(bool) << endl;
}
2.✳的意义
乘号:
int c = a*b;
int a=2,b=3;
声名:
int *i,*j;
解引用:
int a=100;
int *p=&a;
x=*p;
x =100;
3.ASCII码
特殊:
1----------49
A----------65
a----------97
空格------32
4.指针复习
#include<iostream>
using namespace std;
int main()
{
int a = 10, b = 20;
int* p = NULL;
p = &a;
*p = 100;
p = &b;
*p = 200;
return 0;
}
p在此处指的为a和b的地址
*p指的为a和b本身的值
5.判断闰年
#include<iostream>
using namespace std:
void Is_leap()
{
int year;
scanf_s(“%d”,&year);
if((year%4==0&&year%100!=0)||year%400==0)
{
res= true;
}
return res;
else
{
return false;
}
}
6.已知某一年的某一月,求这一月的天数
#include<iostream>
using namespace std;
int Get_YM_Day(int year,int month)
{
int day=0;
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
day=31;
break;
case 4: case 6: case 9: case 11:
day=30;
break;
default:
if(Is_Leap(year)){ day=29; }
else{ day=28; }
} return 0;
}
7.已知某日具体日期,求这是这一年的哪一天
#include<iostream>
using namespace std;
int Get_YM_Day(int year,int month)
{
static const int day[13]={29,31,28,31,30,31,30,31,31,30,31,30,31}
// 0 1 2 3 4 5 6 7 8 9 10 11 12
if (month==2 && Is_Leap(year) )
{
month=0;
} return day[month];
}
int Get_YMD_Total(int year,int month,int day)
{
int day[13]={29,31,28,31,30,31,30,31,31,30,31,30,31}
int sum=0;
if (year<1) return -1;
if (month<1||month>12) return -2;
if (day<1||day>Get_YM_Day(year,month)) return -3;
for(i=1,i<month,++i)
{
sum=sum+Get_YM_Day(year,i);
}
return sum+day;
}