概念填空题
1 面象四特性:抽象封装继承态
2 构造函数作创建象时象赋初值析构函数作释放象占资源
3 根继承基类少C++继承分: 单继承 继承
4 C++进行动态存分配运算符newdelete
5 抽象类纯虚函数:…P153
纯虚函数基类中说明虚函数该类基类中没定义求派生类中必须定义版重新说明纯虚函数
果类少纯虚函数称该类抽象类
6 象拷贝两种方式:浅拷贝 深拷贝
7 变量生存期分:动态生存期 静态生存期
8 C++里逻辑值:非0表示真0表示假
9 C++里函数参数传递方式:值传递址传递引传递(P35例213程序1程序2程序3)
10 静态成员变量属类象享静态成员变量
11 根访问控制C++继承分:公继承私继承保护继承
12 const修饰象意思:象状态修改
13 拷贝构造函数调场合3种分:象作参数构造象时函数实参象赋值时函数返回象时
14 C++里模版包括:函数模版类模版
15 命名空间作
名字空间程序设计者命名存区域名字空间作类似操作系统中目录文件关系名字空间建立相互分隔作域全局标识符分隔开避免产生名字突(P48)
16 类访问属性包括:公私继承
17 虚基类作 P124
果派生类直接基类基类基类终派生类中会保留该间接基类成员份名成员保留基类份成员仅占较存储空间增加访问成天元时困难容易出错C++提供虚基类方法继承间接基类时保留份成员
18 态分类P145
态性指名字定义函数函数执行类似操作相调方式调具功名函数
参数态包含态重载态强制态前两种称通态两种称专态
19 虚函数重载函数较 P153
(1)函数重载处理层次名函数问题虚函数处理类族中派生层次名函数问题前者横重载者理解重载重载:类族虚函数首部相函数重载时函数首部 (2)重载函数成员函数普通函数虚函数成员函数 (3)重载函数调传递参数序列差作调函数虚函数根象调类虚函数 (4)虚函数运行时表现出态功C++精髓重载函数编译时表现出态性
20 类函数否虚函数条件:P151
判断该函数基类虚函数相名称该函数基类虚函数相参数数相应参数类型该函数基类虚函数相返回类型者满足赋值兼容规指针引型返回函数
21 cin cout >> <<
22 根文件中数组织 文件分ascII文件二进制文件
23 强制类型转换:(int)35 int(35)
24 联函数inline P62
该方法思想编译时调函数代码直接嵌入调函数处INLINE函数机制兼顾函数效率两方面点
二程序结果
1 程序结果_____57 510 57_________________(全局变量局部变量问题)
viod myfunction( )
{int y10 cout<
int main( )
{ cout<
cout<
int ret(int a)
{ static int c10
aa+c ca return c }
int main()
{ int a2
for(int i0 i<2 i++) cout<3程序结果________________3________________(指针)
int main( )
{ int a2 Int *b&a a3 cout<<*b }
4程序结果________________3________________(引)
int main( )
{ int a2 int &ba a3 cout<5程序结果________________________________________(参数传递)
int main( )
{ int x(3) y(8)
Swap(x y)
cout<< x<
{ int t ta ab bt }
6程序结果________________________________(参数传递)
int main( )
{ int x(3) y(8)
Swap(&x & y)
cout<< x<
{ int t t*a *a*b *bt }
7程序结果________________4________________(引)
int main( )
{ int a2 int &ba aa+b cout<8程序结果_________________5_______________(数组)
int main( )
{ int a[5]{23456} Int *ba cout<<*(b+3) }
三程序填空
1输入整数位数字反转输出(利运算符 )
int main( ){
int n rd newnum
cin>>n
do{ rd____n10_______ cout<
int main( ){
int i0 j0 n
cin>>n
while(n0){if(n>0)___i++______ if(n<0)__j++______ cin>>n }
cout<<正整数数:<3户输入考试分数(0~100)输出考试等级
int main( ){
int m _cin>>m>>endl_____________
switch(____m10_____) {
case 10
case 9 cout<<优秀 break
case 8 cout<<良 break
case 7 cout<<中等 break
case 6 cout<<格 break
default cout<<格 }
4交换两整数
int main( )
{ int x(5) y(10)
cout<< x<
cout<< x<
{ int t ta ab bt }
5查找数组中元素值5元素返回序号
int main( ){
int n a[10] i0
for(i0 i<10 i++ ) cin>>a[i]
for(i0 i<10 i++ ) if(____a[i]5______) __count<
6查找数组中元素值’b’元素换 B’
int main( ){
char a[10] int i0 j0 n
cin>>a
for(i0 i<10 i++ )
if(______a[i]'b'_______________) {______a[i]'B'_____ cout<
int main( )
{ int x(5) y(10)
cout<< x<
cout<< x<
{ int t ___t*a_________ ____*a*b _____*bt________ }
四编程题
2定义复数类实现两复数类相加相减P206
求:(1)运算符函数重载成员函数(2)运算符函数重载友元函数
#include
using namespace std
class Complex
{public
Complex(){real0imag0}
Complex(double rdouble i){realrimagi}
Complex operator + (Complex &c2)
Complex operator (Complex &c2)
void display()
private
double real
double imag
}
void Complexdisplay()
{cout<<(<
Complex Complexoperator + (Complex &c2)
{
Complex c
crealreal+c2real
cimagimag+c2imag
return c
}
Complex Complexoperator (Complex &c2)
{
Complex c
crealrealc2real
cimagimagc2imag
return c
}
int main()
{
Complex c1(34)c2(510)c3c4
c1display()
c2display()
c3c1+c2
cout<
c4c1c2
cout<
return 0
}#include
class Complex
{public
Complex(){real0imag0}
Complex(double rdouble i){realrimagi}
friend Complex operator + (Complex &c1 Complex &c2)
friend Complex operator (Complex &c1 Complex &c2)
void display()
private
double real
double imag
}
void Complexdisplay()
{cout<<(<
Complex operator + (Complex &c1 Complex &c2)
{
Complex c
crealc1real+c2real
cimagc1imag+c2imag
return c
}
Complex operator (Complex &c1 Complex &c2)
{
Complex c
crealc1realc2real
cimagc1imagc2imag
return c
}
int main()
{
Complex c1(34)c2(510)c3c4
c1display()
c2display()
c3c1+c2
cout<
c4c1c2
cout<
return 0
}
57
#include
using namespace std
class Cat { public Cat(int age){numOfCats++ }
virtual ~Cat() { numOfCats }
static int getnumOfCats() { return numOfCats } private
static int numOfCats }
int CatnumOfCats 0 void telepathicFunction() { cout << There are << CatgetnumOfCats() << cats alive\n }
int main() {
const int maxCats 5
Cat *catHouse[maxCats] int i
for (i 0 i < maxCats i++) { catHouse[i] new Cat(i) telepathicFunction() }
for (i 0 i < maxCats i++) { delete catHouse[i] telepathicFunction() }
return 0 }
411
#include
class Rectangle
{
public
Rectangle(float len float width)
{
Length len
Width width
}
~Rectangle(){}
float GetArea() { return Length * Width }
float GetLength() { return Length }
float GetWidth() { return Width }
private
float Length
float Width
}
void main()
{
float length width
cout << 请输入矩形长度:
cin >> length
cout << 请输入矩形宽度:
cin >> width
Rectangle r(length width)
cout << 长 << length << 宽 << width << 矩形面积:
<< rGetArea () << endl
}
3 编写类成员函数包括:1)接受键盘输入英文句子2)实现条英文句子中字母数统计输出3)输出英文句子函数里进行测试
#include
using namespace std
class Char
{
public
Char(){count0}
void Input()
void show()
void GetCount()
{
cout<<字母数:<
private
char a[100]
int count
}
void CharInput()
{
for(int i0i<100i++)
{
count++
cin>>a[i]
if(a[i]'@') 输入符合@退出循环
break
}
}
void Charshow()
{
for(int i0i
int main(){
Char a
aInput()
ashow()
aGetCount()
return 0}
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档