22 b
a function in any namespace can be accessed in the form of mynamespace::myfunction
example
std::cout << "Dummy\n";
example::dummy();
23 b
structure elements can be accessed using dot or an arrow.
in this case it is accessed as bigRect.length
if bigRect was a pointer variable, then the members are accessed as bigRect->length or (*bigRect).length
24 c
0 is the first position in str2 which is S
5 is the number of characters to replace, which is Smith
when str1 replaces you get the answer as mentioned in c.
25 b
accessor functions are those functions that are used to access member variables.
mutator functions are those functions that are used to modify member variable values.
eg. myclass m
class Toto{
private :
int _age;
public :
void SetAge(int);
int GetAge();
};
void Toto::SetAge(int age){
_age = age;
}
int Toto::GetAge(){
return _age;
}
SetAge is a mutator
GetAge is a accessor
please rate the answer
Given the following code namespace globalType { void.printResult(): } which of the following statements is needed...
QUESTION 10 Which of the following is the correct definition of a function that calculates the area of a rectangle by multiplying its length by its width? The length and width parameters are double values and the function returns a double. double area (double length, double width) return lengthwidth double area( double length, double width) double area length width return double area(double length, width) return length width area(double length, double width) return length width; QUESTION 11 What is the output...
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...
In C++ Given the declaration char str1[15]; char str2[15] = "Good day"; mark the following statements as valid or invalid. If invalid, explain why. NOTE: Assume that the directive #define _CRT_SECURE_NO_WARNINGS has been entered appropriately in the program. a) if(strlen(str1)>=strlen(str2)) str1 = str2; b) if(strcmp(str1,str2)) cout << "The strings are equal";
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...
In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...
The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...
Create a C++ Console project called Lab3a and add the following source document rect_struct.cpp to the project. #include <iostream> #include <iomanip> using namespace std; // This program uses a structure to hold data about a rectangle // PLACE YOUR NAME HERE // Fill in code to declare a structure named rectangle which has // members length, width, area, and perimeter all of which are floats int main() { // Fill in code to define a rectangle variable named box...
Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...
It's a C++ code.
2. Answer the following questions in a word document. 6. What is the output of the following C++ code? (2, 3) int inti - 26 int int2 = 45; int intPtr - Einti; int int2Ptr - Gint2: intPtr -89; int2Ptr - 623 intiptr - int2Ptr intPtr - 80 intl -57 cout << inti «..« int2 << endl; cout << *intiptr «« int2Ptr << endl; 7. Given the following statements: int num; int numPtr write C++ statements...
3. Given that the string variables str1 and str2 contain “you ought to start with logic” and “ou” Respectively, what is the result of each of the following expression? a. str1. length () b. str1. Find (str2) c. str1.substr (4,25) d. str1.substr (4,25). find (str2) e. str1.substr (4,25). find (“logic”), 3) e. str1 substr. (24,5). find (str2. Substr (0,1)) g. str1. find (“end”)