Question 1
An array is NOT:
A - Made up of different data types.
B - Subscripted by integers.
C - A consecutive group of memory chunks.
D - None of the choices.
Question 2
How many times is the body of the loop executed?
int i=1; while(true) { cout << i; if(++i==5) break; }
A - Forever
B - 4
C - 5
D - 6
E - 0
Question 3
What is wrong with the following piece of code fragment?
1 string name; 2 name = “PCC”; 3 switch(name) 4 { 5 case “BCC”: cout << “BCC”; 6 break; 7 case “PCC”: cout <<”PCC”; 8 break; 9 }
A - Default statement is missing.
B - There is an error in Line 2
C - Strings cannot be used with switch statement.
D - Semi colon is missing at the end of the switch statement.
E - None of the choices.
Question 4
What is stored in the variable name result?
string str1= “John Smith”; string str2 = “John Doe”; bool result = (str1 < str2);
A - true
B - false
C - Undefined
D - None of the choices.
E - “John Smith”
F - “John Doe”
Question 5
In a brief sentence describe what is wrong with the following code:
1 int minval(int arr[], int size) 2 { 3 int localmin; 4 for (int i=0; i<size; i++) 5 if (arr[i] < localmin) 6 localmin = arr[i]; 7 return localmin; 8 }
Question 6
After the following code snippet is pre-processed, the statement in Line 5 expands to which of the following:
1 # See rand() in http://www.cplusplus.com/reference/cstdlib/rand/ 2 #include <cstdlib> 3 4 #define R(n) random()%n 5 int value = R(j-i+1);
A - int value = rand()%j-i+1;
B - int value = random()%j-i+1;
C - int value = R(j-i+1)%j-i+1;
D - None of the choices.
Question 7
We have the following 2 char arrays with identical character sequences in them. The easiest way to compare if both string buffers have the same content is to check for the result of arr1==arr2.
char arr1[] = {'p', 'c', 'c'}; char arr2[] = {'p', 'c', 'c'};
A - True
B - False
Question 8
We can copy str1 into str2 by the following:
char str1[10] = "PCC"; char str2[10]; strcpy(str1, str2);
A - True
B - False
Question 9
This question may have 0 to multiple answers. Choose all that apply. Examine the following code and identify the Line number(s) where a bug may exist. Bug is defined as the specific location in line number where the flow of execution may either stop or produce undesirable result:
1 char str[4]; 2 for (int i=0; i<3; i++) 3 str[i]=getchar(); 4 cout << str;
A - Line 2
B - Line 3
C - Line 4
D - None of the choices.
Question 10
The following statement is CORRECT:
char str[3] = "pcc";
A - True
B - False
Question 11
Generally, we write error handlers (namely, functions that are designed to catch input, functional, or output errors) for errors that are caught at compile time.
A - True
B -False
Question 12
This question may have 0 to multiple answers. Choose all that apply. Which of the following is TRUE about a function:
A - Passing lots of arguments into a function is costly compared to alternatives.
B - Having too many function calls in a program slows it down.
C - A function declaration tells the compiler about a function's name, return type, and parameters.
D - A function can return AT MOST 1 value back to its caller.
Question 13
When passing an array into a function as its parameter, we must also pass in the array's size into the function as another parameter.
A - True
B - False
Question 14
This question may have 0 to multiple answers. Choose all that apply. Converting from data type _______ to data type ______ will result in the loss of data.
A - short, long
B - float, double
C - int, char
D - char, bool
E - None of the choices.
Question 15
A data type that can have values ONLY between the range 0 to 65535 is a:
A - 2-byte int
B - 4-byte int
C - 2-byte unsigned int
D - 4-byte unsigned int
Question 16
This question may have 0 to multiple answers. Choose all that apply. Consider the following for loop:
for (int x = 1; x < 5; increment) { cout << x + 1 << endl; }
If the last value printed is 5, which of the following can be used for increment?
A - x++
B - ++x
C - x += 1
D - None of the choices.
E - x--
F - --x
J - x -= 1
Question 17
If a do…while structure is used:
A - Counter-controlled iteration is not possible.
B - An infinite loop cannot take place.
C - An off-by-one error cannot occur.
D - The body of the loop will execute at least once.
E - None of the choices.
Question 18
In C++, the condition (4 > y > 1):
A - Does not evaluate correctly and should be replaced by (4 > y && y > 1).
B - Evaluates correctly and could be replaced by (4 > y && y > 1).
C - Does not evaluate correctly and should NOT be replaced by (4 > y && y > 1).
D - Evaluates correctly and could NOT be replaced by (4 > y && y > 1).
Question 19
Which of the following initializes a vector<int> with a list initializer:
A - vector integers{1, 2, 3, 4, 5, 6};
B - vector<int> integers(1, 2, 3, 4, 5, 6);
C - vector<int> integers{1, 2, 3, 4, 5, 6};
D - None of the choices.
E - vector<int> integers[1, 2, 3, 4, 5, 6];
Question 20
This question may have 0 to multiple answers. Choose all that apply. Assuming var is an int, and you apply an increment operation on var in a statement:
A - var++ adds 1 to var, returning the new var before the semicolon.
B - ++var adds 1 to var, returning the new var before the semicolon.
C - var++ adds 1 to var, returning the old var before the semicolon.
D - ++var adds 1 to var, returning the old var before the semicolon.
E - None of the choices.
Question 21
This question may have 0 to multiple answers. Choose all that apply. Which of the following is a valid way to retrieve the length of a C++ string, str?
A - str.length();
B - strlen(str);
C - strlen(str.c_str())+1;
D - None of the choices.
E - str.size();
Question 22
An array is a sequence of objects allocated in contiguous memory. That is, all elements of an array can be of different types and there are no gaps between them in the sequence.
A - True
B - False
Question 23
The following statements compile in C++:
int arr[10]; arr[-1] = 1; arr[10] = 2;
A - True
B - False
Question 24
The support for C-style strings are in <cstring>
A - True
B - False
Question 25
What is the length of the resulting C-style string, str, after strcpy()?
char str[100]; strcpy(str, "C++");
A - 4
B - 3
C - 100
D - 101
Question 26
C++ style string is terminated by '\0'.
A - True
B - False
Question 27
Assuming str is an non-empty C-style string, is the following True or False?
sizeof(str) == strlen(str);
A - True
B - False
Question 28
If the variable x has the original value of 3.3, what is the output value after the following?
cout << static_cast<int>(x);
A - 3
B - 2
C - 3.3
D - 4
E - undefined
F - 3.0
Question 29
What is the value returned by the following function?
int function() { int value = 30; return value + 5; value += 10; }
Question 30
Assert terminates the program with a message when its boolean argument turns out to be TRUE.
A - True
B - False
Question 31
Multiple arguments going into to a function as parameters are separated by a
A - commas ','
B - period '.'
C - semicolons ';'
D - comments
Question 32
The functions pow(), sqrt(), and fabs() are found in which include file?
A - cstdlib
B - stdlib
C - iostream
D - cmath
E - std
Question 33
This question may have 0 to multiple answers. Choose all that apply. How do you concatenate two C++ strings, str1 and str2?
A - concate(str1, str2);
B - strconcate(str1, str2);
C - str1 = str2;
D - str1.add(str2);
E - str1 += str2;
For the remaining questions, use this Problem Description. You are asked to examine an arbitrary C++ string, and generate a list of characters and their occurrences, in ASCII order, from that string.
Example:
For an input string of "P C C?", we can see the repeated characters are ' ', 'C', 'P' and '?' with an empty space occurring 2 times, 'C' occurring 2 times, 'P' occurring 1 time, and '?' occurring 1 time. In ASCII order we have the following, with their count:
: 2 C: 2 P: 1 ?: 1
Question 34
Based on the Problem Description, the input may be the combination of any one of the 128 characters in the ASCII table (Links to an external site.)Links to an external site.. Write a STATEMENT (not the entire program) to create/instantiate an array of 128 characters called arr, either statically or dynamically.
NOTE: if you choose to allocate arr dynamically, please also include a second statement to dynamically deallocate it.
12pt
Paragraph
0 words
Flag this Question
Question 352 pts
Based on the Problem Description, we need to keep the character count for every one of the 128 possible characters. Which of the following statements illustrates the use of arr (array created from the last problem) to increment the ASCII_CHARACTER count by 1? ASCII_CHARACTER can be any one of the first 128 characters in the ASCII Table (Links to an external site.)Links to an external site. (not the Extended ASCII Table).
arr[ASCII_CHARACTER-97]++;
arr[ASCII_CHARACTER] = ASCII_CHARACTER++;
arr[ASCII_CHARACTER]++;
arr[ASCII_CHARACTER-65]++;
None of the choices.
Flag this Question
Question 367 pts
Based on the Problem Description and the previous questions, write a short code snippet (not the entire problem) to generate a dictionary of letter occurrences. Namely, print a list of input characters and their occurrences from an arbitrary C++ string, str. You may use cout() to print them to the console. Cut and paste your code snippet into the text box.
Input:
string str = "P C c?";
Output:
Your output is a character list in the ascending ASCII order (namely space ' ' appearing before '?', which appears before 'C' , which appears before 'P'. Finally, the lower case 'c' appears last):
: 2 ?: 1 C: 1 P: 1 c: 1
Constraints/Assumptions:
Rubric:
1) answer A
the elements of array are of same data type
2)answer B
the loop runs for i=1 i=2,i=3,i=4 when i=4 this statement (++i)==5 is true so break statement works and loop is broken
3)answer C
switch statements work only for integers
4)answer B false
s1 < s2 : A string s1 is smaller than s2 string, if either, length of s1 is shorter than s2 or first mismatched character is smaller.
In this example length of John Doe is smaller than John Smith
5)local min is not initialised so it will have garbage value
6)answer B
int value = random()%j-i+1;
7)answer B false
char arrays can not be compared using == because arr1 and arr2 gives the address where the first element of char array is stored
8)False
string can be copied using strcpy(str2,str1) not strcpy(str1,str2)
According to HomeworkLib policy in one question with multiple parts we have to answer minimum 4 parts but i have answered 8 parts
.If you have any doubt in any 8 of these .you can ask in comment section And do positive rate the answer
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...
Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
Using C++ Use the below program. Fill in the code for the 2 functions. The expected output should be: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: #include #include #include using namespace std; //Assume a line is less than 256 //Prints the characters in the string str1 from beginIndex //and inclusing endIndex void printSubString( const char* str1 , int beginIndex, int endIndex ) { } void printWordsInAString( const char* str1 ) { } int main() { char str1[] = "The fox jumps over the...
In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...
C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...
The first issue: write a program in C #, which does the following: 1- Read two string strings str1 and str2 entered by the user so that each one is composed from at least five characters. 2- Transferring the first two letters of the str1 to the end of the str2, then writing each of them. 3- Delete the first and last characters of the str2 string, then write the new string that results from Deletion process. 4- Moving two...
Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...
when i run it is still be "false" i don't know why. could you help me fix it and tell me which part is wrong??? specific answer is better thanks!!! Problem 6: (4 pts): Write a function that takes as an input parameter a string. It should return a Boolean value indicating whether the string is a palindrome or not. INPUT: “mom"->true “palindrome”->false “amanaplanpanama"->true 3 #include <iostream> #include <string.h> I using namespace std; string function(string str); int main() { function("palindrome");...