The following questions refer to the UML class diagram at the right.
class Ceres
{
...
};
class Vesta
{
private:
Ceres* c;
}; |
class Pallas
{
...
};
class Hygiea
{
private:
Pallas p;
}; |
|
class Doris
{
...
};
class Cybele
{
public:
void function()
{
Doris d;
...
}
}; |
class Hektor;
class Camilla
{
private:
Hektor* h;
};
class Hektor
{
private:
Camilla* c;
}; |
|
class Psyche
{
...
};
class Fortuna
{
public:
void function(Psyche p);
}; |
class Europa
{
...
};
class Juno : public Europa
{
...
}; |
class foo
{
public:
foo();
};
class bar : public foo
{
public:
________________
};
Which of the following are valid bar constructors (including the initializer lists)? (Mark all that are valid.)
class foo
{
public:
foo(int x);
};
class bar : public foo
{
public:
________________
};
Which of the following are valid bar constructors (including the initializer lists)? (Mark all that are valid.)
class foo
{
public:
foo(int x, int y);
};
class bar : public foo
{
public:
};
Which of the following are valid bar constructors (including the initializer lists)? (Mark all that are valid.)
class foo
{
public:
void function1() { /* do stuff here */ }
void function2() { /* do stuff here */ }
};
class bar : public foo
{
public:
void function1() { /* do stuff here */ }
};
int main()
{
bar b;
b.function1();
return 0;
}
class foo
{
public:
void function1() { /* do stuff here */ }
void function2() { /* do stuff here */ }
};
class bar : public foo
{
public:
void function1() { /* do stuff here */ }
};
int main()
{
bar b;
b.function2();
return 0;
}
class foo
{
public:
void function1() { /* do stuff here */ }
void function2() { /* do stuff here */ }
};
class bar : public foo
{
public:
void function1() { function1(); }
};
int main()
{
bar b;
b.function1();
return 0;
}
class foo
{
public:
void function1() { /* do stuff here */ }
void function2() { /* do stuff here */ }
};
class bar : public foo
{
public:
void function1() { foo::function1(); }
};
int main()
{
bar b;
b.function1();
return 0;
}
class foo
{
private:
int counter;
public:
foo(int c) : counter(c){}
};
class bar : public foo
{
public:
bar(int c) : foo(c){}
void function() { cout << counter << endl; }
};
int main()
{
bar b(10);
b.function();
return 0;
}
class foo
{
private:
int my_data;
public:
foo(int d) : my_data(d) {}
void print() { cout << my_data << endl; }
};
class bar
{
private:
int my_data;
public:
bar(int d) : my_data(d) {}
void print() { cout << my_data << endl; }
};
int main( )
{
foo obj1(5);
bar obj2(10);
obj2.print();
return 0;
}
Use the UML class diagram to answer the following questions, which are about the initializer list needed to complete the class B constructor:
B(int w, int x, int y, int z) : ______________________;class Bar
{
private:
int x;
char y;
public:
Bar(int a, char b) : x(a), y(b) {}
};
class Foo
{
private:
string i;
Bar my_bar;
public:
Foo(int a, char b, string c) : __________, i(c) {}
};
Fill in the blank to complete the Foo constructor to initialize the member variables in the Bar superclass.
class Bar
{
private:
. . . .
public:
void display()
{
. . . .
}
};
class Foo
{
private:
int i;
Bar my_bar;
public:
void display()
{
__________________;
cout << i << endl;
}
};
Fill in the blank to complete the Foo display function to print the member variables in my_bar.
class Bar
{
private:
. . . .
public:
void display()
{
. . . .
}
};
class Foo
{
private:
int i;
Bar* my_bar;
public:
void display()
{
if (my_bar != nullptr)
_________________ ;
cout << i << endl;
}
};
Fill in the blank to complete the Foo display function to print the member variables in my_bar.
class foo
{
private:
string name;
double salary;
};
class bar
{
private:
char* name;
double salary;
};
class Bar
{
private:
int count;
double balance;
public:
Bar(int a_count, double a_balance):(a) ________ {}
void display()
{
cout << count << " " << balance << endl;
}
};
class Foo : public Bar
{
private:
string name;
public:
Foo(string a_name, int count, double balance):
(b) __________________________________________
void display()
{
(c) _______________________; // display inherited Bar
out << name << endl;
}
};
Fill in the blanks to complete the program.
class Bar
{
private:
int count;
double balance;
public:
Bar(int c, double b) : (a) _____________________;
void display()
{
cout << count << " " << balance << endl;
}
};
class Foo
{
private:
string name;
Bar my_bar;
public:
Foo(string n, int c, double b) : (b) ______________________;
void display()
{
(c) ___________________________;
cout << count << endl;
}
};
Fill in the blank to complete the program.
class Bar
{
private:
int count;
double balance;
public:
Bar(int c, double b) : (a) _____________________;
void display()
{
cout << count << " " << balance << endl;
}
};
class Foo
{
private:
string name;
Bar* my_bar = nullptr;
public:
Foo(string n) : (b) ______________________;
~Foo() { (c) _________________________________; }
void set_bar(int c, double b)
{
(d) _____________________________;
(e) _____________________________;
}
void display()
{
(f) ___________________________;
cout << count << endl;
}
};
Fill in the blanks to complete the program.