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

Using java, create a class called MyString that has one String called word as its attribute...
Using java, create a class called MyString that has one String called word as its attribute and the following methods: Constructor that accepts a String argument and sets the attribute. Method permute that returns a permuted version of word. For this method, exchange random pairs of letters in the String. To get a good permutation, if the length of the String is n, then perform 2n swaps. Use this in an application called Jumble that prompts the user for a...
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 } }
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters...
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters in mystring that also occur in the string ‘Python’. Using above function, write a program that repeatedly prompts the user for a string and then prints the number of letters in the string that are also in string ‘Python’. The program terminates when the user types an empty string.
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...
Let's get some practice implementing a known interface. Create a public class named MyString. MyString should...
Let's get some practice implementing a known interface. Create a public class named MyString. MyString should provide a public constructor that accepts a single String argument. You should reject null Strings in your constructor using assert. MyString should also implement the Java Comparable interface, returning 1 for a positive result and -1 for a negative result. Normally Strings are compared lexicographically: "aaa" comes before "z". MyString should compare instances based on the length of its stored String. So MyString("aaa") should...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT