Question

In: Computer Science

For each of the questions that follow, fill in the blanks. Blanks are denoted by --[N.]--,...

For each of the questions that follow, fill in the blanks. Blanks are denoted by --[N.]--, where N is an upper-case Roman numeral.

(a) Complete the following code so that the loop executes 10 times (3) int j = −−[I.]−−;

int i=1;

while ( −−[II.]−− ) {

i = i + −−[III.]−−; }

(b) Complete the following function which sorts C-strings into alphabetic order. (4)

Page 4

void bubbleSort( char names[ ][COLS] , int count) {

int pass , index ;
char temp[COLS];
for ( pass = 0; pass < count; pass++ )

}

for ( index = 0; index < (count −1); index++ ) if ( −−[IV.]−− )

{

}

// swap t h e names

−−[V.]−− −−[VI.]−− −−[VII.]−−

(c) You are given the following incomplete program to test whether a given password is valid or not. The (6) rules for a valid password are given by:

1. A password must contain at least one lowercase letter, one uppercase letter and one decimal digit 2. The password length must be at least 7 characters.

int main() {

char∗ password ;
password = new char[250];

// Read the password

cin >> password;

//Test whether the password is valid

if (isValidPassword(password)) {

cout << ”The password complies with the rules” << endl; }

else

{

cout << ”The password does not comply with the rules” << endl; }

delete [ ] password ; return 0 ;

}

Complete the function to test for a valid password.

bool isValidPassword( const −−[VIII.]−−) {

const int MINLEN = 7;
int lowerCount = 0 , upperCount = 0 , digitCount = 0, index = 0; bool valid = false ;

−−−[IX.]−− (password[index] != ’\0’) {

if ( −−[X.]−− (password[index]) ) digitCount++;

else if ( −−[XI.]−− (password[index] )) lowerCount++;

else if ( −−[XII.]−− (password[index] )) upperCount++;

index++;

}

Page 5

if ((digitCount > 0) && (lowerCount > 0) && (upperCount > 0) && (strlen(password) >= MINLEN))

valid = true; −−[XIII.]−−

}

(d) Complete the following struct definition. (1)

struct Bus{
−−[XIV.]−− routeName ;

int routeLength ; };

  1. (e) Given a struct (2)

    struct Cart {
    string material ;

    double volume ;

    int cap[3]; };

    and the following code

    int main() {

    Cart c = −−[XV.]−−; }

    Instantiate c with the following values: • tin

    • 70.3
    • {1,2,3}

  2. (f) Use the following prompts to define a class Cube that contains information about a cube’s length and volume.

i. Complete the declaration for the Cube class by filling in the missing code statements. The class should (3) contain a public interface to modify and retrieve the length of the cube and to compute its volume.

class Cube {

−−[XVI]−− int length ;

−−[XVII]−− −−[XVIII]−− −−[XIX]−− −−[XX]−−

// access specifier

// access specifier
// setLength function prototype // getLength function prototype // getVolume function prototype

};

  1. Implement the getVolume function to return the cube’s volume as follows: V = l3, where V and l are (2)

    the cube’s length and volume, respectively.

    int −−[XXI]−− {

    return −−[XXII]−− }

  2. Why is it advisable to not have a variable volume to store the cube’s volume value? (1)

Solutions

Expert Solution

1.) set j = 10 and make i increment until it reaches j value.

int j = 10;

int i = 1;

while(i <= 10){

i = i+1;

}

2.) use strcmp to compare the string and strcpy() to swap string using temp variable.

void bubbleSort( char names[ ][COLS] , int count) {

int pass , index ;
char temp[COLS];
for ( pass = 0; pass < count; pass++ )

for ( index = 0; index < (count −1); index++ ) if (strcmp(names[index],names[index+1] < 0)

{

strcpy(temp, names[index+1]);

strcpy(names[index+1], names[index]);

strcpy(names[index], temp);

}

}

3.) use isdigit() to check for digits, islower() to check for lowercase, isupper() to check for uppercase

int main() {

char∗ password ;
password = new char[250];

// Read the password

cin >> password;

//Test whether the password is valid

if (isValidPassword(password)) {

cout << ”The password complies with the rules” << endl; }

else

{

cout << ”The password does not comply with the rules” << endl; }

delete [ ] password ; return 0 ;

}

Complete the function to test for a valid password.

bool isValidPassword( const char password[]) {

const int MINLEN = 7;
int lowerCount = 0 , upperCount = 0 , digitCount = 0, index = 0; bool valid = false ;

while (password[index] != ’\0’) {

if ( isdigit(password[index]) ) digitCount++;

else if (islower(password[index] )) lowerCount++;

else if ( isupper (password[index] )) upperCount++;

index++;

}

4.) declare busName as string

struct Bus{

string routeName ;

int routeLength ; };

5.) provide the initialzation value inside {} seperated by ,

struct Cart {
string material ;

double volume ;

int cap[3]; };

and the following code

int main() {

Cart c = {"tin", 70.3, {1,2,3}}; }

6.) decalre lenght under private and setlenght(), getLength(), getVolume() under public.

class Cube {

private:

int length ;

public:

void setLength(int l) ;

int getLength();

int getVolume();

// access specifier

// access specifier
// setLength function prototype // getLength function prototype // getVolume function prototype

};

make the funtion getVolume() return lenght*length*length

int getVolume() {

return length*length*length; }

it is not advisable to set another variable for volume, because it is a simple calcuation which can done without seperately allocating memory space for it.


Related Solutions

Fill in the blanks in each of the following statements
Fill in the blanks in each of the following statementsa) --------- allows you to build JavaFx GUIS using drag and drop techniques.b) The elements in the scene graph are called --------------c) A(n) ----------- file contains the description of a JavaFX GUI.d) The method ---------------- is called by FMXLLoader before the GUI is displayed
Use below terms to fill in blanks in the sentences that follow. Each term is used only once.
  Use below terms to fill in blanks in the sentences that follow. Each term is used only once. contingency table control variable correlated cross-products dependent variable direction of association expected values gamma correlation coefficient higher order gammas independent variable
 negative Nominal
 ordinal
 positive 
spurious association statistical elaboration statistically significant strength of association When conducting a two-way chi-square test to decide whether one variable probably influences a second variable, we compare the actual (observed) frequencies to the (1) ________________________, which...
Fill-in the blanks of the following table and answer the following questions.
Fill-in the blanks of the following table and answer the following questions.                                Year                         Nominal GDP $                Real GDP $                      GDP Deflator       20052,000, 0002,000,000_____________20062,310,000___________         105Find the GDP Deflator in year 2005.Find the Real GDP in year 2006.Which GPD matters, nominal or real GDP? Why?Did the economy grow in year 2006? Why yes, why not?
Please fill in the blanks in the following table:          Present                Future        &n
Please fill in the blanks in the following table:          Present                Future                   Interest                   Time to          Value                   Value                      Rate                     Maturity          $20,000                                                6%                      34 years                                    $200,000                    7%                      12 years          $55,000          $111,419.91                                             18 years          $90,000          $207,408.40                 11%                           
C++ Fill in the blanks please You are required to fill in the blanks in this...
C++ Fill in the blanks please You are required to fill in the blanks in this program. Consider that: -In main, the variables price and quantity were given the names of p (double) and q (int), respectively. -In the getData function, the parameters associated with the main variables p and q were called pp and pq, respectively. // Prototype: Do not include the names // of the variables in the prototype void getData (FILLTHEBLANK , FILLTHEBLANK); int main () {...
Fill in the blanks for the following questions (Possible answers have been provided after each blank)...
Fill in the blanks for the following questions (Possible answers have been provided after each blank) In terms of the Federal income and transfer taxes, identify what is accomplished in the following disclaimer situations occurring in 2017. a. Lester dies without a will and is survived by a daughter, Nora, and a grandson, Nick. The major asset in Lester's estate is stock worth $3,500,000. Because Nora is already well-off and in ill health, she disclaims Lester's property. By disclaiming her...
Fill in the blanks in each of the following statements: a) The _________ states that every...
Fill in the blanks in each of the following statements: a) The _________ states that every column in a primary key must have a value, and the value of the primary key must be unique b) The ________ states that every foreign-key value must appear as another table's primary-key value. c) A(n) ________ in a pattern indicates that a string matching the pattern can have zero or more characters at that location in the pattern. d) Java DB is the...
Fill in the missing blanks in each of the following equations a) _______   → 85At217 +...
Fill in the missing blanks in each of the following equations a) _______   → 85At217 + 2He4 b) 94Pu241→95Am241 + ____________ c) 11Na19→10Ne19 +________ d) 34Se75+ _____ → 33As75 e) 95Am241 →93Np237 +____ f) ______ → 92U233 + -1e0 g) 93Np237 → ______ + 2He4 h) 35Br75 → ______ + +1e0
fill in the blanks.1. the statement of financial position is also knownas a(n) ?...
fill in the blanks.1. the statement of financial position is also known as a(n) ?2. the inventory account is found on the ?3. net sales less cost of goods sold yields ?4. prepaid expenses are a ?5. which of the following accounts represents the market value of the company ?6. capital stock is found on the ?7. the wages accrual adjusting entry credits a liability account and debits.8. if a liability increases, then.9. if an owners equity account increases then...10....
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase...
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase or decrease. I2(s) + 5F2(g) ⇌ 2IF5(g) A decrease in volume results in a Blank 1 in pressure which will Blank 2 the amount of IF5.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT