Question

In: Computer Science

Question 11 mystring.length() or mystring.size() will return the length of the string in mystring. Question 11...

Question 11

mystring.length() or mystring.size() will return the length of the string in mystring.

Question 11 options:

True
False

Question 12

To access an element of an array of structures you use the ________ operator.

Question 12 options:

Dot

Bitwise

Logical

Comparison

Question 13

Question 13 options:

What would be printed from the following C++ program?

#include

#include

using namespace std;

struct Point

{

int x;

int y;

};

void makeTriangle(Point p[]);

int main()

{

Point p[3];

int i;

makeTriangle(p);

cout<<"The triangle consists of the following coordinates:\n";

for(i=0 ;i<3;i++)

cout<<"("<

return 0;

}

void makeTriangle(Point p[]){

p[0].x = 200;

p[0].y = 20;

p[1].x = 150;

p[1].y = 100;

p[2].x = 300;

p[2].y = 100;

}

Question 14 :

A ________ contains the memory address of a variable that in turn contains the specific value.

Question 15

In the programming segment below, the output is “30”?

int numbers[] = {10, 20, 30, 40, 50};

cout << "The third element in the array is ";

cout << *numbers + 2 << endl;

Question 15 options:

True
False

Question 16

The ________ _______ is used to ______ a pointer.

Question 17

mustring.end() returns an iterator pointing to the last character of the string in mystring

Question 17 options:

True
False

Question 18

The first n characters of the character array str are appended to mystring using which statement below.

Question 18 options:

mystring.assign(str, n)

mystring.append(str, n)

mystring.append(sx, n)

mystring.append(str, n, x)

Question 19

_______ is the library needed to conduct character testing (such as isalpha()).

Question 20

__________________ returns a copy of a substring. The substring is n characters long and begins at position x of mystring

Question 20 options:

mystring.substr(x-1, n)

mystring.substr(x, n-1)

mystring.substr(x, n)

mystring.substr(x, n+1)

mystring.substr(x+1, n)

Solutions

Expert Solution

Question 11:

Correct Answer: True

Explanation:

The given statement is true because both function will return the length of the string.

For example:

string str = "abc";
cout<<str.length()<<endl;
cout<<str.size()<<endl;

OUTPUT:

3
3

Question 12:

Correct Answer: Dot

Explanation:

A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.

So, only first option is the correct option.

Question 13:

Correct Answer:

The triangle consists of the following coordinates:
(200, 20)
(150, 100)
(300, 100)

Explanation:

The given program source code has syntx error in the below statement:

cout<<"("<

To correct the syntax error, the given statement should be replaced with the below statement:

cout<<"("<<p[i].x<<", "<<p[i].y<<")"<<endl;

After replacing the above statement, the output of the given source code will be:

The triangle consists of the following coordinates:
(200, 20)
(150, 100)
(300, 100)


Question 14:

Correct Answer: pointer variable

Explanation:

A pointer variable is a special type of variable that is used to store the address of another variable which has a similar data type as the pointer data type. The dereferenced operator '*' is used to access the value stored at that location that is stored by the pointer variable.

For example:

int a = 10;

int *b = &a;

Here, the variable 'b' is a pointer variable that stores the address of an integer type variable.


Related Solutions

Given a string of at least 3 characters as input, if the length of the string...
Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint. -------------------------------------------------------------- public class Class1 { public static String midString(String str) {     //Enter code here } }
A string of length L = 1 is held fixed at both ends. The string is...
A string of length L = 1 is held fixed at both ends. The string is initially deformed into a shape given by u(x, t = 0) = sin^2(πx) and released. Assume a value of c2 = 1. Find the solution u(x, t) for the vibration of the string by separation of variables.
Which of this method of class String is used to obtain a length of String object?...
Which of this method of class String is used to obtain a length of String object? What is the output of the below Java program with WHILE, BREAK and CONTINUE? int cnt=0; while(true) { if(cnt > 4)    break;    if(cnt==0) {     cnt++; continue; }   System.out.print(cnt + ",");   cnt++; } 1,2,3,4 Compiler error 0,1,2,3,4, 1,2,3,4,
string string_long_division (string dividend, string divisor) { string ans; //code in here return ans; } Create...
string string_long_division (string dividend, string divisor) { string ans; //code in here return ans; } Create a function that takes in 2 strings called dividend (is a string because this could be greater than the size of an int) and divisor (is a string because this could be greater than the size of an int) and performs long division on them and returns the result as a string. It would be preferred if the code was written in c++. THIS...
Project: Given a string s and an integer array indices of the same length. The string...
Project: Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the i th position moves to indices[i] in the shuffled string. Return the shuffled string. Example: Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output: "leetcode" Explanation: As shown, "codeleet" becomes "leetcode" after shuffling. You need to do: Create a class called ShuffledStringApp. Keeping class StringOperation and IO in util package. In this project, you will...
Recall that a 5-bit string is a bit strings of length 5, and a bit string...
Recall that a 5-bit string is a bit strings of length 5, and a bit string of weight 3, say, is one with exactly three 1’s. a. How many 5-bit strings are there? b. How many 5-bit strings have weight 0? c. How many 5-bit strings have weight 1? d. How many 5-bit strings have weight 2? e. How many 5-bit strings have weight 4? f. How many 5-bit strings have weight 5? g. How many 5-bit strings have weight...
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return...
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return -1 } public boolean areArrays(int[] arr1, int[] arr2){ // 1. initial check: both arrays need to have the same length, return false if not the same // 2. return true if both given arrats are equals(same values in the same indices), false otherwise } public boolean areArraysEqual(String[] arr1, String[] arr2){ // 1. initial check: both arrays need to have the same length, return false...
Consider an elastic string of length L whose ends are held fixed. The string is set...
Consider an elastic string of length L whose ends are held fixed. The string is set in motion with no initial velocity from an initial position u(x, 0) = f(x). Let L = 10 and a = 1 in parts (b) and (c). (A computer algebra system is recommended.) f(x) = 16x L ,      0 ≤ x ≤ L 4 , 4,      L 4 < x < 3L 4 , 16(L − x) L ,      3L 4...
A string of length 1.0m has a mass/length of 2.4 g/m and is under 460N of...
A string of length 1.0m has a mass/length of 2.4 g/m and is under 460N of tension. It is vibrating in its third harmonic (n = 3). 1. What is the frequency of the standing wave? The vibrating string produces a sound wave and sits near a half-open tube of length L. The speed of sound is 343m/s. 2. For what minimum value of L does the sound wave produced by the vibrating string resonate with the tube (i.e., coincide...
QUESTION 11 In util package, public class Example { public static void showMessage( String s ){...
QUESTION 11 In util package, public class Example { public static void showMessage( String s ){ ....... } public static int getInt( String prompt ){ ....... } } Using these method you see above to create a main method in your class called MyExam in the different package to get input and output. The output will tell the user what number is entered. If you entered a 5, the output will be: "The number you entered is 5.". QUESTION 12...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT