Look at the following class definition, which statements are legal and which are
ID: 3738012 • Letter: L
Question
Look at the following class definition, which statements are legal and which are illegal. Explain why
class Vehicals{
private:
int sedan;
int trucks;
int planes;
int boats;
publics:
Change() { sedans= trucks= planes= boats= 0; }
Change(int s, int t, int p, int b) { sedans= s ; trucks= t; planes= p; boats= b; }
void add(int s=0, int t=0, int p=0, int b=0)
{ sedans+= s; trucks += t; planes += p; boats+= b; }
void subtract(int s=0, int t=0, int b=0, int p=0)
{ sedans-= s; trucks -= t; planes -= p; boats-= b; }
}
Explanation / Answer
Answer is as follwos:
class Vehicals{ // statement is legal, syntax is true.
private: // legal statement
int sedan; //legal statement
int trucks; //legal statement
int planes; // legal statement
int boats; // legal statement
publics: // illegal statement syntax is public not publics
Change() { sedans= trucks= planes= boats= 0; } // illeagal statement becasue it should have an return type
Change(int s, int t, int p, int b) { sedans= s ; trucks= t; planes= p; boats= b; } // illeagal statement becasue it should have an return type
void add(int s=0, int t=0, int p=0, int b=0) // Statement is legal , according to syntax
{ sedans+= s; trucks += t; planes += p; boats+= b; } // Statement is legal , according to syntax
void subtract(int s=0, int t=0, int b=0, int p=0) // Statement is legal , according to syntax
{ sedans-= s; trucks -= t; planes -= p; boats-= b; } Statement is legal , according to syntax
} //Ilegal statement , it should end with" }; " not only with "}" .
Bold words are the answer to the corresponding statement.
if there is any query please ask in comments....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.