文档库 最新最全的文档下载
当前位置:文档库 › 2015年C++程序设计上机实践题

2015年C++程序设计上机实践题

2015年C++程序设计上机实践题
2015年C++程序设计上机实践题

2015 C++程序设计上机实践题

Chapter 1

?熟悉VC的开发环境

?熟悉编译、运行C++程序的基本过程。

1.Example:

#include

using namespace std;

int main()

{

int a,b;

a = 627;

b = 365;

cout<

return 0;

}

Chapter 2

?继续熟悉VC开发环境,能独立开发,编译,运行程序。

?熟悉C++程序结构

?编写程序理解declaration, variable, expression,<<, +的语法规则。

?Arithmetic expression

2.Book p64-65 2,3,5,6,8

3.编程:定义两个Char型变量,分别赋值’a’,’b’。实现大小写字母转换,并输出,即变

量输出值应为’A’,’B’。

Chapter 3

?Type coercion and type casting

?Function call

?Output function

?String function

4.P104-105 2,6,7,10,12

5.上机验证以下表达式的运算结果:

char a;

int b;

a = ‘2’;

b = 3;

int c;

c = a +b;

// please print the value of a, b and c

float d;

d = float(c)/b;

//please print the value of b,c and d.

Chapter 4

?Input from keyboard

?File Operation

6.请完成以下程序,并测试运行结果

#include

using namespace std;

int main ()

{

char char1;

char char2;

char char3;

char char4;

cout << "Input four characters. Press Return." << endl;

//please use cin and >> to read four characters

cout << char1 << char2 << char3 << char4;

return 0;

}

7.请完成以下程序,并测试运行结果

#include

using namespace std;

int main ()

{

char char1;

char char2;

char char3;

char char4;

cout << "Input four characters. Press Return." << endl;

// please use get function to read four characters .

cout << char1 << char2 << char3 << char4;

return 0;

}

8.请输入不同的值,并测试运行结果

第一组值为:2 3 4回车5 6 7回车20 30回车

第二组值为:2,3,4回车5,6,7回车20,30回车

#include

using namespace std;

int main ()

{

cout << "inter the values as shown" << endl;

int a, b, c, d, e, f, g, h;

cin >> a >> b >> c;

cin.ignore(80, '\n');

cin >> d >> e >> f;

cin.ignore(80, '\n');

cin >> g >> h;

cout << " a " << a << " b " << b << " c " << c << endl;

cout << " d " << d << " e " << e << " f " << f << endl;

cout << " g " << g << " h " << h << endl;

return 0;

}

9.Book P148 10,11

10.Book P149 2

Chapter 5

Rational and logical expression

11.BOOK P194-P195 2,3,7,10,11,12

12.Programming Problems Book P197 2

13.Programming Problems Book P198 8

14.有一函数

-1 (x<0)

y={0 (x=0)

1 (x>0)

编二个不同的程序,输入一个x值,输出y值。

Chapter 6

?Looping

?while statement

15.Book P231-232 5,8,10,12

16.Programming Problems Book P234 4

17.Programming Problems Book P235 5

18.Write a program 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 111

(10)

0!1!2!

e E E-≈+++???+>

Chapter 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 Postconditions

22.Book P272-273 12,16,18

23.Programming Problems Book P276 7

Chapter 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 Program

24.编写程序验证以下代码的运行结果

int alpha = 3;

int beta = 20;

if (beta > 10)

{

int alpha = 5;

beta = beta + alpha;

cout << alpha << ' ' << beta << endl;

}

cout << alpha << ' ' << beta << endl;

25.Book p313 1,11,14

26.Programming Problems Book P315 3

Chapter 9

?Switch Statement for Multi-way Branching

?Do-While Statement for Looping

?For Statement for Looping

?Using break and continue Statements

27.Book P342-343 2,12

28.Programming Problems Book P345 5,6(两个题写一个答案即可) Chapter 10

?External and Internal Representations of Data

?Integral and Floating Point Data Types

?Using Combined Assignment Operators

?Prefix and Postfix Forms of Increment and Decrement Operators

?Using Ternary Operator(三元运算符)

?Using Type Cast Operator

?Using an Enumeration Type

?Creating and Including User-Written Header Files

29.Book P395-396 6,7,14

Chapter 11

?Meaning of a Structured Data Type

?Declaring and Using a struct Data Type

?C++ union Data Type

?Meaning of an Abstract Data Type

?Declaring and Using a class Data Type

?Using Separate Specification and Implementation Files

?Invoking class Member Functions in Client Code

?C++ class Constructors

30.Enhance the TimeType class by adding a new member function WriteAmPm. This function

prints the time in 12-hour rather than 24-hour form, adding AM or PM at the end. Write the function specification and definition in .h and .cpp file.

31. A rational number is a number that can be expressed as a fraction whose numerator and

denominator are integer. Examples of rational numbers are 0.75, which is 3/4 and 1.125, which is 9/8. The value PI is not a rational number; it cannot be expressed as the ratio of two integers.

Working with rational numbers on a computer is often a problem. Inaccuracies in floating-point representation can yield imprecise results. For example, the result of the C++ expression 1.0/3.0*3.0 is likely to be a value like 0.999999 rather than 1.0.

Design, implement and test a Rational Class that represents a rational number as a pair of integers instead of a single floating-point number. The segment of client code can be.

Rational result;

As the very least, you should provide the following operations:

(1)Set function. This function MUST be called prior to any of the other member functions.

(2)Arithmetic operations that add, subtract, multiply and divide. These functions should return

a rational object.

(3)An output operation that displays the value of a rational object in the form

numerator/denominator, e.g. 2/3 .

Chapter 12

?Declaring and Using a One-Dimensional Array

?Passing an Array as a Function Argument

?Using const in Function Prototypes

?Using an Array of struct or class Objects

?Using an enum Index Type for an Array

?Declaring and Using a Two-Dimensional Array

?Two-Dimensional Arrays as Function Parameters

?Declaring a Multidimensional Array

32.填空完成代码

// Program Reverse reads numbers into an array

// and prints them out in reverse order.

#include

#include

using namespace std;

const int MAX = 10;

int main ()

{

int numbers[MAX];

ifstream inData;

int value;

int index;

inData.open("reverse.dat");

for (index = 0; index < MAX; index++)

{

// FILL IN Code to read value

// FILL IN Code to store value into numbers }

for (index = MAX - 1; index >= 0; index--)

// FILL IN Code to write numbers on the screen return 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 numbers[MAX];

ifstream inData;

inData.open("reverse.dat");

//找最大值

//找最小值

//找平均值

return 0;

}

34.Book P506 2,4,5,6

35.Book P510 4

36.用筛法求100以内的素数。

37.将一个数组中的元素值按逆序重新存放。

38.求一个3×3矩阵对角线元素之和。

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 Arrays

39.Book P563 2,6,7

40.Programming problem Book P564 4

Chapter 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 Functions

41.阅读并理解

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 Function Definitions

?Understanding How Recursion Works

?Writing Recursive Functions

45.int Power ( int x, int n )

X为底数,n为指数;

考虑当n>=0时该如何实现;

考虑当n可能为任意整数时该如何实现;

46.P637 1,3,4,

47.P640 1,2

48.有数组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 &

?Declaring and Using Pointer Variables

?Using the Indirection (Dereference) Operator *

?The NULL Pointer

?Using C++ Operators new and delete

?Meaning of an Inaccessible Object

?Meaning of a Dangling Pointer

?Link struct

?引用

50.请用动态分配内存的方法生成整型数组,对数组进行初始化,求其最大值,最小值,并

进行排序。

51.生成一个单链表,表头指针为h,节点的KEY分别为1到N,N为用户任意输入的一个

整数。

NODE *h;

struct NODE {

int KEY;

NODE * next;

}

相关文档