中山大学C视频课件第6章_黎培兴剖析
1;2;3;4;5;6;7;8;9;#include iostream.h
void main(void)
{
char key[ ] = {a,c,b,a,d};
char c;
int ques = 0, numques = 5, numcorrect = 0;
cout Enter the numques question tests: endl;;; while (cin.get(c))
{ if (c != \n)
if (c == key[ques])
{ numcorrect++;
cout ;
}
else cout *;
else
{ cout Score
float(numcorrect)/numques*100 %;
ques = 0; // reset variables
numcorrect = 0;
cout endl;
continue;
}
ques++;
}
};运行结果:
acbba
** Score 60%
acbad
Score 100%
abbda
* ** Score 40%
bdcba
***** Score 0%;13;存储顺序
按行存放,上例中数组a的存储顺序为:;分行给二维数组赋初值
例如:static int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
将所有数据写在一个{}内,按顺序赋值
例如:static int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
可以对部分元素赋初值
例如:static int a[3][4]={{1},{0,6},{0,0,11}};;16;17;#include iostream.h
void RowSum(int A[ ][4], int nrow)
{ int sum;
for (int i = 0; i nrow; i++)
{
sum = 0;
for(int j = 0; j 4; j++)
sum += A[i][j];
cout Sum of row i is sum endl;
}
} ;void main(void)
{ int Table[3][4] = {{1,2,3,4},{2,3,4,5},{3,4,5,6}};
for (int i = 0; i 3; i++)
{ for (int j = 0; j 4; j++)
cout Table[i][j] ;
cout endl;
}
RowSum(Table,3);
};运行结果:
1 2 3 4
2 3 4 5
3 4 5 6
Sum of row 0 is 10
Sum of row 1 is 14
Sum of row 2 is 18
;21;22;23;24;//6-5.cpp
#includeiostream.h
#include Location.h
Location::Location( )
{ X=Y=0;
coutDefault Constructor called.endl;
}
Location::Location(int xx,int yy)
{ X=xx;
Y=yy;
cout Constructor called.endl;
};Locatuon::~Location( )
{
coutDestructor called.endl;
}
void Location::Move(int x,int y)
{
X=x;
Y=y;
};int main( )
{
coutEntering main...endl;
Location A[2];
for(int i=0;i2;i++)
A[i].Move(i+10,i+20);
coutExiting main...endl;
return 0;
};运行结果:
Entering main...
Default Constructor called.
Default Constructor called.
Exiting main...
您可能关注的文档
- 中小学寒假社会实践作业设计方案.doc
- 中小学教师信息采集表(培训用).docx
- 中小学教师公开招聘考试学科专业知识《体育》试题试卷(上).doc
- 葡萄沟(第二课时).ppt
- 中小学教师计算机考试基础知识2016-3-12.docx
- 中小学数学教学衔接问题研究.doc
- 葡萄酒文化与鉴赏葡萄酒的品尝.ppt
- 中小学公共安全教育--公共交通遇险自救.pptx
- 中小学教育质量监测态势与实证研究(王旭东-温州教育评估院).pptx
- 中小学校会计制度.doc
- 某镇领导班子2025年度民主生活会对照检查材料.docx
- 高级中学党政办公室主任2025年度述职述廉报告.docx
- 在镇“锤炼作风提效能,凝心聚力建新功”主题春训活动动员部署会上的讲话.docx
- 在2026年春季开学教职工会议上的讲话.docx
- 公司党支部2025年度组织生活会对照检查材料.docx
- 在树立和践行正确政绩观学习教育动员部署会议上的讲话.docx
- 专题党课:筑牢作风“防火墙” 展现司法新担当.docx
- 在树立和践行正确政绩观学习教育专题研讨会上的发言材料.docx
- 在公司2026年度党建暨党风廉政大会上的讲话.docx
- 在县委党的建设工作领导小组会议上关于开展树立和践行正确政绩观学习教育部署工作的讲话.docx
原创力文档

文档评论(0)