True/False: Circle one 1. True/False Variable and functions identifiers can only
ID: 3751293 • Letter: T
Question
True/False: Circle one 1. True/False Variable and functions identifiers can only begin with alphabet and digit. 2. True/Fale Array sizes can be non-constant variables. 3. True/Fa Array sizes must be known at compile time. 4. True /False An array can have size of 0 S. True / False int m # 156; won't compile because the types do not match. 6. True /False int n 11/S; will allocate memory for n and initialize with the value 2. 7. True/False Array indices begin with the number 1 8. True/False You can define multiple functions with the same identifier 9. True/Fal Variables declared local to a function are still accessible after the function completes execution. 10. True/False structs by default have private access specification. 11. Suppose you're tasked with fixing a function definition that does not work as intended. The function is supposed to compare two strings and set the count to the number of identical characters, two characters are identical if they are the same character and are in the same position in the cstring. This function will be case sensitive so the character a is not the same as 'A. Note that cstrings are just character arrays that have 10 as their last character, for example char name[7]hary" might looks like this in memory: Usage of this function might look like: int count8 compareCstrings( tacocat",TACOCAT", count) / should set count to 8 compareCstrings( Harry""Malfoy", count); comparecstrings( SMC", "SBCC, count); // should set count to1 // should set count to 2 Currently the function definition is: void compareCstrings (const char stri[], const char str2[], int count) &count int index; while (stri!e 1l str2 ( if (stristr) &count++; index+; Identify the errors in the above implementation and rewrite the function so that it satisfies specification. Try to keep the general form of the original code, you should not have to add or remove any lines of code, just modify the existing ones Page 1 of6Explanation / Answer
1)False
A variable in C++ should begin with a letter or an underscore
2)False
Array size has to be constants or a variable declared as constant.
3)True
All static array sizes should be known at compile time.
4)False
In c++ it is illegal to have an array of size zero.
5)False
It will compile and m will be initialized with 15 ,ignoring the ractional part.
6)True
Since it is declaration and definition combined , memory will be allocated and it will be assigned 2 after ignoring the fractional part (11/5=2.2)
7)False
In C++ ,array indices begin with 0.
8)True
Identifier can be same but singnature (prototype) has to be different.
9)False
Local variables can be accessed only within its scope.
10)False
By default, structs have public access.
11)
Update code highlighted.Reason for change given as comments
void compareCstrings(const char str1[],const char str2[],int &count){//count has to be passed as //reference as its being used in calling function also
count=0; //& is address of operator .you cannot assign 0 to an address
int index=0;//should be initialized to zero
while((str1[index]!='' && str2[index]!=''))//compare value at each indices
{
if(str1[index]==str2[index])
count++;
index++;
}
}
----------------------------------------------------------------------------------------------------
12)
a)first
Calculates the sum of two integers passed .Then the sum is subtracted by 3 , till sum becomes less than 3.The sum is the returned.
second
It takes in a string(a) and an integer(b).It returns the charater at index b of string a.
third
It takes two values b (an integer ) and a string (a) .a is passed as reference.It firstly saves the substring at location 3*b,3*b+1 and 3*b+2. The in string a char at locations 3*b,3*b+1 and 3*b+2 is replaced with '.' .
b)We we define functions with same name it is known as polymorphism.To obtain polymorphism same identifier functions should have different parameter list (ie number or type o arguments must be different.)
c) d)f) cannot be answered since it requires your student id
13)
Hotel::Hotel() {
for(int i=0;i<FLOORS;i++)
for(int j=0;j<ROOMSPERFLOOR;j++)
m_rooms[i][j]='E';
}
----------------------------------------------------------------
bool Hotel::reserve(int roomnum) {
int floor=roomnum/100;
int room=roomnum%100;
if(m_rooms[floor-1][room-1]='E')
{
m_rooms[floor-1][room-1]='R';
return true;
}
return false;
}
------------------------------------------------------------------------------------
bool Hotel::cancel(int roomnum) {
int floor=roomnum/100;
int room=roomnum%100;
if(m_rooms[floor-1][room-1]='R')
{
m_rooms[floor-1][room-1]='E';
return true;
}
return false;
}
--------------------------------------------------------------------
bool Hotel::checkIn(int roomnum) {
int floor=roomnum/100;
int room=roomnum%100;
if(m_rooms[floor-1][room-1]='R')
{
m_rooms[floo-1r][room-1]='O';
return true;
}
return false;
}
----------------------------------------------------------------
bool Hotel::checkOut(int roomnum) {
int floor=roomnum/100;
int room=roomnum%100;
if(m_rooms[floor-1][room-1]='O')
{
m_rooms[floor-1][room-1]='E';
return true;
}
return false;
}
------------------------------------------------------------------
int Hotel::numEmpty(int floor) {
int count=0;
if(0<floor || floor>FLOORS)//if floor is invalid
return -1;
for(int i=0;i<ROOMSPERFLOOR;i++)
{
if(m_rooms[floor-1][i]=='E')
count++;
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.