联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2021-01-23 06:07

PAPER CODE ....................ELEC362...............PAGE....1........OF ..............4..........................CONTINUED

MOCK EXAM PAPER

(Open book test)

Application development with C++

TIME ALLOWED: 3 Hours

INSTRUCTIONS TO CANDIDATES

The numbers in the right hand margin represent an approximate guide to the marks available

for that question (or part of a question). Total marks available are 100.

For all questions requiring a code, make sure the code is well commented as comments are

part of the total mark of the code.

For all questions requiring a code, the code submitted in the answer sheet must be machine

readable (copy and paste the code into your answer sheet).

Answer ALL Questions.

PAPER CODE ....................ELEC362...............PAGE....2........OF ..............4..........................CONTINUED

1 a) Write a C++ programme that reads a sentence, input by the user and displays a

breakdown of how many each letter in the English alphabets was repeated. For

example, the sentence “how are you” will display:

25

a appeared 1 time/s

b appeared 0 time/s

c appeared 0 time/s

d appeared 0 time/s

e appeared 1 time/s

The list continues for the 26 letters. You can assume the following simplifications

about the input to the programme:

-All letters are lower case.

-No symbols or numbers will be in the sentence.

- No error handling is required.

b) Draw a flow chart of an algorithm you propose for a C++ programme used to book

a flight ticket. The programme will be used by a travel agent to do the following

tasks (no code is required):

10

- List all passengers on a given flight.

- Retrieve information of a passenger.

Total

35

PAPER CODE ....................ELEC362...............PAGE....3........OF ..............4..........................CONTINUED

2. a) Explain the process of generating an executable file from the source code files. 6

b) Explain what friend functions are used for. 6

c) Define what the destructor of a class is, give an example of what it can be used for

(no code is required).

4

d) You are given the following code, specify whether the variables are allocated on static

or dynamic memory:

int i{ }; 2

int &r=i; 2

double Array[5]; 2

char *letter{nullptr}; 2

int *number= new int(0); 2

vector<double> data; 2

Total

28

PAPER CODE ....................ELEC362...............PAGE....4........OF ..............4..........................END

3. a) Explain the difference between a vector and a list? Give an example of a situation

where a list is more suitable than a vector in a code. What is the main disadvantage

of using a list over a vector? (No code is required).

7

b) From basic datatypes, create a class “Sphere” and a class “Cube”, which are

used to describe geometrical shapes to be used in a CAD programme. The

following code from the main function will be run to test your code. The

comment in every line explains the used function or operator, etc.

30

Cube Cube1; // Initialising a cube with side length of 1

Sphere Sph1(5); // Initialising a sphere with radius 5

Cube1.setSide(5); // changes the side length of Cube1 to 5

cout << "The surface Area of Cube1 is " << Cube1.SurfArea()<<" and the

surface area of Sph1 is " << Sph1.SurfArea()<< endl;

// The function SurfArea() returns the surface area of the shape

double TotVol = Cube1.Vol() + Sph1.Vol();

// Adds the volumes of the shapes, the function Vol() gives the volume

of the shape

cout << "The total volume is "<< TotVol;

The output of this code when it runs should be:

The surface Area of Cube1 is 150 and the Surface Area of Sph1

is 314.159

The total volume is 648.598

No error handling is required. For simplicity you can define the entire code

in a single file (header files are not needed).

Total

37


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp