0% found this document useful (0 votes)
35 views13 pages

C++ Programming Tutorials for UMaT

Uploaded by

Eben Wonder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views13 pages

C++ Programming Tutorials for UMaT

Uploaded by

Eben Wonder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

University of Mines And Technology (UMaT-Tarkwa)

Computer Science and Engineering Department


Software Engineering (CE 276)

BY

INTRODUCTION
RICHARD KOFI ANNAN
1

(COMPUTER SCIENCE AND ENGINEERING)


 Write a single C++ statement or line that accomplishes each of the following:
 Print the message "Enter two numbers".
 Define three float data-type variables “result” and “b” and “c”.
 Assign the values to the variables “b” and “c” by inputting them
University of Mines And Technology (UMaT-Tarkwa)

from the keyboard.


Computer Science and Engineering Department

 Assign the product of variables b and c to variable “result”.


 Display the value in “a”.
Software Engineering (CE 276)

 Assign the difference of variables b and c to variable “result”.


 Display the value in “result”.
 Assign the sum of variables b and c to variable “result”.
 Display the value in “result”.
 Assign the quotient of variables b and c to variable “result”.
 Display the value in “result”.
 Assign the modulus of variables b and c to variable “result”.
 Display the value in “result”.

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 2
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Write a program to compute the following (remember to include cmaths
library)
 Print the message "Enter two numbers".
 Define three float data-type variables “result” and “b” and “c”.
University of Mines And Technology (UMaT-Tarkwa)

 Assign 𝑏120 to the variable z;


Computer Science and Engineering Department

 Display the value in the “z”


 Assign 𝑐 70 to the variable y
Software Engineering (CE 276)

 Display the value in the “y”


 Find the square root of “y” ( 𝑦) and assign to “y”.
 Display the value in “result”.
 Find the cubed root of “z” ( 3 𝑧) and assign to “z”.
 Find log10 (𝑦 + 𝑧) and assign to “result”.
 Display the value in “result”.
 Find log 2 (log10 𝑧 + log10 𝑦) and assign to “result”.

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 3
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Display the value in “result”.
 Find log 2 (log10 𝑧 + log10 𝑦) and assign to “result”.
 Display the value in “result”.
 Find the exponential values of z (𝐸𝑥𝑝 𝑧 ) and y (𝐸𝑥𝑝 𝑦 ) and assign to “result”.
University of Mines And Technology (UMaT-Tarkwa)

 Display the value in “result”.


Computer Science and Engineering Department

 Assign the computation of this (𝑏5 + 𝑐 10 ) in the variable result.


 Display result rounded up to the nearest integer. (using ceil(value))
Software Engineering (CE 276)

 Display result rounded up to the nearest integer. (using round(value))


 Display result rounded up to the nearest integer. (using nearbyint(value))
 Display result rounded down to the nearest integer. (using floor(value))
 Display result with the decimal portion truncated. (using trunc(value))
 Display the absolute value of the results. (using abs(value))
 Display the absolute value of the results. (using fabs(value))

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 4
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
Write a C++ program to perform the following

 Print the message "Enter two numbers".


 Define two int data-type variables “b” and “c”.
University of Mines And Technology (UMaT-Tarkwa)

 Check whether if b is greater than c (b>c) using the isgreater()


Computer Science and Engineering Department

function and ternary operator and display to the user a suitable


statement.
Software Engineering (CE 276)

 Check whether if b is greater than or equal to c (b>=c) using the


isgreaterequal() function and ternary operator and display to the
user a suitable statement.
 Check whether if b is less than or equal to c (b<=c) using the
islessequal() function and ternary operator and display to the
user a suitable statement.
 Check whether if b is less than c (b>c) using the isless() function
and ternary operator and display to the user a suitable statement.
 Check where if b is less that c or b is greater than c using
islessgreater() function and ternary operator and display to the
user a suitable statement.

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 5
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
Write a simple program to allow phone users buy airtime, data bundle or use
mobile money services by selecting an option as displayed below.
***************************************************
* Welcome to MTN USSD Application Services *
University of Mines And Technology (UMaT-Tarkwa)

* Press 124: For Airtime Checking *


Computer Science and Engineering Department

* Press 170: For Mobile Money Services *


* Press 138: For Internet Bundle Services *
Software Engineering (CE 276)

***************************************************
Program Control:
 If the selection is 124 Display “Welcome to the MTN Air Time
Checking Services”.
 If the selection is 170 Display “Welcome to the MTN Mobile
Money Services”.
 If the selection is 138 Display “Welcome to the MTN Internet
Bundle Services”.

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 6
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Write a simple program to allow phone users buy airtime, data bundle or use
mobile money services by selecting an option as displayed below.
***************************************************
* Welcome to MTN USSD Application Services *
University of Mines And Technology (UMaT-Tarkwa)

* Press 124: For Airtime Checking *


Computer Science and Engineering Department

* Press 170: For Mobile Money Services *


* Press 138: For Internet Bundle Services *
Software Engineering (CE 276)

* Press 134: To Load Airtime Credit *


***************************************************
Program Control:
 If the selection is 124 Display “Welcome to the MTN Air Time
Checking Services”.
 Else If the selection is 170 Display “Welcome to the MTN
Mobile Money Services”.
 Else If the selection is 138 Display “Welcome to the MTN
Internet Bundle Services”.
Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]
MSc. Telecommunications Engineering (University of Sunderland – UK). 7
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
• Else If the selection is 134
Display “Welcome to the MTN Load Airtime Credit Services”.
• Prompt the user to input the respective digit on voucher
card
University of Mines And Technology (UMaT-Tarkwa)

• input voucher digits


Computer Science and Engineering Department

• If digits is greater than or less than 14 Display “Wrong


voucher entered”.
Software Engineering (CE 276)

• Else Display “Correct Voucher Digits Entered”.


• Else Display “!!!!!OOPs!!!!! Service does not exist.”

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 8
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Implement the program in the FIVE using the switch selection control
structure.

Write a simple program to allow phone users buy airtime, data bundle or use
mobile money services by selecting an option as displayed below. The program
University of Mines And Technology (UMaT-Tarkwa)

should not terminate if the user makes the wrong choice.


Computer Science and Engineering Department

*********************************************************
Software Engineering (CE 276)

* Welcome to MTN USSD Application Services *


* Press 124: For Airtime Checking *
* Press 170: For Mobile Money Services *
* Press 138: For Internet Bundle Services *
* Press 0: exit *
*********************************************************

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 9
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Write a program that take ten values from the user and print out the values
that are even and also the odd ones. Sum the odd numbers and display the
sum. Sum the even numbers and display the sum.

 (Summing Integers) Write a program that uses a for statement to sum the
University of Mines And Technology (UMaT-Tarkwa)

sequence of even integers from 1 to 100. Display the sum.


Computer Science and Engineering Department

 (Summing Integers) Write a program that uses a for statement to sum the
Software Engineering (CE 276)

sequence of odd integers from 1 to 100. Display the sum.

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 10
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Write a program to display the multiplication table of any integer value as
input by the user. The multiplication table should start from 1 to 50 as shown
in the sample below;
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
University of Mines And Technology (UMaT-Tarkwa)

2 x 4 = 8
Computer Science and Engineering Department

2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
Software Engineering (CE 276)

2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
2 x 11 = 22
2 x 12 = 24
2 x 13 = 26
2 x 14 = 28
2 x 15 = 30
2 x 16 = 32
2 x 17 = 34
2 x 18 = 36
2 x 19 = 38
2 x 20 = 40
. . . . .
. . . . .
2 x 50 = 100

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 11
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 (Averaging Integers) Write a program that uses a for statement to calculate the
average of several integers. Prompt the user to enter the number of values to
be added and find the average of the numbers keeping in mind the last value
to be entered is the sentinel i.e. 9999.

 Write a program that calculates the squares and cubes of the numbers from 0
University of Mines And Technology (UMaT-Tarkwa)

to 50 and uses tabs to print the following table of values.


Computer Science and Engineering Department

number square cube


0 0 0
Software Engineering (CE 276)

1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
. . .
. . .
. . .

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 12
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).
 Find the Smallest Integer) Write a program that uses a for statement to
find the smallest of several integers. Assume that the first value read
specifies the number of values to be entered.
University of Mines And Technology (UMaT-Tarkwa)

 Write a program that converts lower case letter to uppercase letter (i.e.
Computer Science and Engineering Department

from A to Z and a to z) and print them out as shown in the sample


output below (on systems that use the ASCII character set).
Software Engineering (CE 276)

Sample output
a A
. .
. .
. .
z Z

Prepared by: Richard Kofi Annan [Email: rkannan@[Link]]


MSc. Telecommunications Engineering (University of Sunderland – UK). 13
BSc. Computer Science and Engineering (University of Mines and Technology-Ghana).

You might also like