Tuesday, 22 May 2018

C++ Fundamentals Practice Questions 1

Fundamentals of programming

Question 1: Write an algorithm that repeatedly asks a user for his/her name. When the user enters the word “done” the algorithm prints “goodbye!” and then terminates. Here is an example execution. The user’s input has been shown in bold. If given the same inputs, your algorithm should behave exactly the same way.
What is your name? Linda
What is your name? Toby
What is your name? Mary
What is your name? Dave
What is your name? Done

Also draw its flow chart in Microsoft Word.

Print out a table of numbers formatted as follows:
number(i)                      square                                cube
0                                    0                                   0
1                                    1                                   1
2                                    4                                   8
You can insert tabulations in the output stream by using the '\t' escape sequence, similar to the '\n' sequence we have already seen for carriage return. Example:
cout << "number\t square\t cube\t\n";
will output the first line of the table. you might want to space things out more by inserting multiple '\t' tabulation spaces between columns.
Do it with ‘\t’ first and then setw().
note: the table starts at zero, the table ends at 5.You will need to declare a  variable (int i) and then increment its value till it reaches 5.

No comments:
Write comments