1、2015 C+程序设计上机实践题Chapter 1 熟悉 VC 的开发环境 熟悉编译、运行 C+程序的基本过程。1. Example:#include using namespace std;int main()int a,b;a = 627;b = 365;coutusing namespace std;int main ()char char1;char char2;char char3;char char4;cout to read four characterscout using namespace std;int main ()char char1;char char2;char
2、char3;char char4;cout using namespace std;int main ()cout a b c;cin.ignore(80, n);cin d e f;cin.ignore(80, n);cin g h;cout 0)编二个不同的程序,输入一个 x 值,输出 y 值。Chapter 6 Looping while statement15. Book P231-232 5,8,10,1216. Programming Problems Book P234 417. Programming Problems Book P235 518. Write a progra
3、m that reads a file of student scores for two classes (any size) and finds each class average and two class average. 19. 一球从 100 米高度落下,每次落地后跳回原高度的一半,再落下。编程求它在第 10 次落地时,共经过距离为多少米?第 10 次落地后的反弹有多高?20. (百钱买百鸡)雄鸡 7 元 1 只,母鸡 5 元 1 只,小鸡 1 元 3 只。花 100 元钱,买 100只鸡,如果雄鸡、母鸡和小鸡都必须有,则雄鸡、母鸡和小鸡各买几只?21. 求 e 值。 6(0)0
4、!2!EChapter 7 Writing a Program Using Functional Decomposition Writing a Void Function for a Task Using Function Arguments and Parameters Differences between Value Parameters and Reference Parameters Using Local Variables in a Function Function Preconditions and Postconditions22. Book P272-273 12,16
5、,18 23. Programming Problems Book P276 7Chapter 8 Local Scope vs. Global Scope of an Identifier Detailed Scope Rules Determining the Lifetime of a Variable Writing a Value-Returning Function for a Task Some Value-Returning Functions with Prototypes in Header Files cctype and cmath Stub Testing a Pro
6、gram24. 编写程序验证以下代码的运行结果int alpha = 3;int beta = 20;if (beta 10)int alpha = 5;beta = beta + alpha;cout #include using namespace std;const int MAX = 10;int main ()int numbersMAX;ifstream inData;int value;int index;inData.open(“reverse.dat“);for (index = 0; index = 0; index-)/ FILL IN Code to write num
7、bers on the screenreturn 0;33. 填空完成代码/ Program reads numbers into an array/ and Find the max min average number of the array. #include #include using namespace std;const int MAX = 10;int main ()int numbersMAX;ifstream inData;inData.open(“reverse.dat“);/找最大值/找最小值/找平均值return 0;34. Book P506 2,4,5,635.
8、 Book P510 436. 用筛法求 100 以内的素数。37. 将一个数组中的元素值按逆序重新存放。38. 求一个 33 矩阵对角线元素之和。Chapter 13 Meaning of a List Insertion and Deletion of List Elements Selection Sort of List Elements Insertion and Deletion using a Sorted List Binary Search in a Sorted List Declaring and Using C Strings Using typedef with Ar
9、rays39. Book P563 2,6,740. Programming problem Book P564 4Chapter 14 Structured Programming vs. Object-Oriented Programming Using Inheritance to Create a New C+ class Type Using Composition (Containment) to Create a New C+ class Type Static vs. Dynamic Binding of Operations to Objects Virtual Member
10、 Functions41. 阅读并理解 AboutClass 下的代码AboutClass2 下的代码42. 上机阅读 Class ExtTime 的定义。问题:在客户方的代码中能够访问 ExtTime 中的哪些方法?请通过上机实践验证你的想法。43. P614 1,2,3,4,5 请用一个程序完成,并且编写客户方的代码测试你定义类。44. P615 10,11,12,13,14,15 请用一个程序完成,并且编写客户方的代码测试你定义类。Chapter 15 Meaning of Recursion Base Case and General Case in Recursive Functio
11、n Definitions Understanding How Recursion Works Writing Recursive Functions45. int Power ( int x, int n )X 为底数,n 为指数;考虑当 n=0 时该如何实现;考虑当 n 可能为任意整数时该如何实现;46. P637 1,3,4,47. P640 1,248. 有数组 int array =0, 1, 2, 3, 4, 5, 6, 7, 8, 9,用递归方法实现求最小值、求和。递归函数原型:int Min (int arr , int n); int Sum (int arr , int n);49. 递归实现:顺序读入字符(以? 结束),然后以和输入相反的次序输出读入的字符。Chapter 16 Append Pointer Using the Address-Of Operator struct NODE int KEY;NODE * next;