Folder101   Home Notes Quiz Assigns Info  
Forum Forum
101 Home 101
 
  C++ Level 2

Practice Quiz 6 - Working with Strings and Characters


There are 10 questions in this quiz

Question 1: Multiple Choice       

Which one of the following functions returns an integer value from a string?

Choice 1 atoi()
Choice 2 strlen()
Choice 3 strcmp()
Choice 4 (integer)

Question 2: Multiple Choice       

Examine the following code.

      int len;
      len = strlen("howdy partner");

What is the value of len?

Choice 1 10
Choice 2 11
Choice 3 12
Choice 4 13

Question 3: Multiple Choice       

Examine the following code.

      int result;
     
char str[10] = "Hi there!";
      result = strcmp(str, "Hi there!");

What would the value of result be?

Choice 1 2
Choice 2 1
Choice 3 0
Choice 4 -1

Question 4: Multiple Choice      

Examine the following code.

      char FirstName1[15] = "Angela";
      char FirstName2[15] = "Ang";

      result = strncmp(FirstName, LastName, 3);

      cout << result;

What would the value of result be?

Choice 1 2
Choice 2 1
Choice 3
0
Choice 4 -1

Question 5: Multiple Choice       

Examine the following code.

      char strBuffer[7];
      strncpy(strBuffer, "hello",5);
      cout <<
strBuffer << endl;

What would the output be?

Choice 1 hello¦¦¦¦
Choice 2 hello
Choice 3 hello/0
Choice 4 hello/0/0

Question 6: Multiple Choice     

Examine the code below.    

      char str[] = “1234.5”;
      int num;
      num = atoi(str);
      cout << “number = ” << num << endl;

 What will be output?    

Choice 1 number = 1234
Choice 2 number = 1234.5
Choice 3 1234 = num
Choice 4 number = "1234"

Question 7: Multiple Choice       

Examine the following code.

      int ch = 100;
      cout << "The ASCII value of " << ch << " is " << 100 << endl;

What would the output be?

Choice 1 The ASCII value of A is 100
Choice 2 The ASCII value of B is 100
Choice 3 The ASCII value of c is 100
Choice 4 The ASCII value of d is 100

Question 8: Multiple Choice       

Examine the code below.    

      char str1[] = "0895-673-9900";
      char str2[]= "0000 is your telephone code";
      double num;
      strncpy(str2, str1, 4);
      cout << str2 << endl;

 What will be output?    

Choice 1 0895
Choice 2 0000
Choice 3 0000 is your telephone code
Choice 4 0895-673-9900 is your telephone code

Question 9: Multiple Choice       

Examine the following code.

      char s1[] = "Howdy";
       char s2[20];

      for (int index = 0; index < strlen(s1); index++) {
            s2[index] = toupper(s1[index]);
      }
      s2[index] = '\0';

 What will the output be?

Choice 1 howdy
Choice 2 HOWDY
Choice 3 HOWDY\0
Choice 4 Howdy

Question 10: Multiple Choice       

Examine the code below.

      char str1[] = "1234.5";
      char str2[] = "abcdefghi";
      strncpy (str2,str1, 6);
      cout << atof(str2) << ", " << atoi(str2);

What will be output to the console from the following code?

Choice 1 abcd1234.5, abcd1234;
Choice 2 1234.5, 1234;
Choice 3 1234, 1234.5;
Choice 4 abcd, efghi;