Statement | Word |
---|---|
|
|
Example | Name |
---|---|
|
|
void foo(int x = 10, int y = 20) { cout << x << " " << y << endl; } -------------------------------------- foo();
void foo(int x = 10, int y = 20) { cout << x << " " << y << endl; } -------------------------------------- foo(15);
void bar() { . . . } void bar(int x = 10) { . . . }
public class person { private string first; private string last; private int age; public person(string f, string l, int a) : first(f), last(l), age(a) {} }
class person { string first; string last; int age; person(string f, string l, int a) : first(f), last(l), age(a) {} };
class person { string first; string last; int age; public: person(string f, string l, int a) : first(f), last(l), age(a) {} };
class person { private: string first; string last; int age; public: person(string f, string l, int a) : first(f), last(l), age(a) {} };
class person { public: string first; string last; int age; person(string f, string l, int a) : first(f), last(l), age(a) {} };
Student |
---|
-name : string |
+Student(n : string, g : double) |
class Student { private string name; private double gpa; public Student(string n, double g) : name(n), gpa(g) {} };
class Student { private: string name; double gpa; public: Student(string n, double g) : name(n), gpa(g) {} };
class Student { private: string name; double gpa; public: Student(string n, double g) : n(name), g(gpa) {} };
class Student { private: name string; gpa double; public: Student(n string, g double) : name(n), gpa(g) {} };
foo* f = new foo;Which statement is valid?
Fraction |
---|
-numerator : int |
+fraction(n : int, d : int) |
Foo |
---|
-count : int |
+Foo(a_count : int) |
area.h: class area { private: int width; int height; public: area(int w, int h) : width(w), height(h) {} }; area.cpp: area::area(int w = 5, int h = 10) { // a lot of code goes here }What are the three errors in the above code?
class alpha { private: int beta; public: alpha(int b) : beta(b) {} };Write a complete member function named add that adds two instances of alpha together and returns a new alpha object that represents the sum. The sum of two alpha objects is defined as the sum of their beta member variables.
string name;write an appropriate prototype for an accessor or getter function for name.
Person |
---|
-name : string |
«constructor» |