Practical 09 answer.docx - UECS1643 Fundamentals Of Programming Practical 9Answer Guidelines Part A(Understanding Concepts 1 Given the program below

Practical 09 answer.docx - UECS1643 Fundamentals Of...

This preview shows page 1 - 6 out of 13 pages.

UECS1643 Fundamentals Of Programming Practical 9Answer Guidelines Part A(Understanding Concepts) 1 Given the program below, answer the following questions. (a) What is the output if the input is the following? i 5 Alphanumeric character Digit ii P Alphanumeric character Uppercase letter iii (Tab key) Whitespace iv g Alphanumeric character Lowercase letter v ? Some other character (b) Why code ch = getchar(); is usedinstead of cin>>ch; ? Because object cin cannot be used to read whitespace characters, for example space, tab, newline, etc. Whereas, getchar() function can read all types of characters. 2 Given the program below, answer the following questions. 1
Image of page 1
UECS1643 Fundamentals Of Programming (a) What is the output if the input is the following? i) h tolower of h returns h toupper of h returns H ii) Y tolower of Y returns y toupper of Y returns Y iii) 3 tolower of 3 returns 3 toupper of 3 returns 3 (b) What will be the output if a non-alphabet character is sent to function tolower() or toupper() ? The tolower() or toupper() function will return back the unchanged non-alphabet as output. 3 The following program displays a table showing the characters from a to z together with their ASCII codes. (a) Run the program and observe the output. 2
Image of page 2
UECS1643 Fundamentals Of Programming (b) Modify the code above to get the following output: #include <iostream> using namespace std; int main(void) { char ch; cout << "Letter\tASCII Code\n"; for (ch = 'Z'; ch >= 'A'; ch--) cout<<" "<<ch<<"\t " << (int)ch<< endl; return 0; } . 4. s1 length: 4 s2length: 4 3
Image of page 3
UECS1643 Fundamentals Of Programming s1: good s2 from 2nd element: job s1: good job s1: good job jo 5. (a) -1 (b) 1 (c) 0 6. 0 1 1 1 1 1 -1 0 1 1 1 1 -1 -1 0 1 1 1 -1 -1 -1 0 1 1 -1 -1 -1 -1 0 1 -1 -1 -1 -1 -1 0 7. The following program asks the user to enter a word. The program will display the word backward. It is assumed that the word will not exceed 20 characters. The program displays the characters one by one starting from the last character. Answer the following questions: 4
Image of page 4
(a) Why header file <cstring> is included? Function strlen() requires this header file (b) What is the output if the word entered is “program” ?
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 13 pages?

  • Spring '16
  • -
  • ASCII, len

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture