Find the errors in the following class and explain how to correct them #include
ID: 3546008 • Letter: F
Question
Find the errors in the following class and explain how to correct them
#include <iostream>
using namespace std;
class A {
int num ;
public :
A(int x) {
num = x ; }
};
class B {
string name ;
A object ;
B(string n,int x) {
name = n ;
object(x) ;
}
}
int main () {
B ob("Moh",435) ;
system ("pause") ;
return 0 ; }
#include <iostream>
using namespace std;
class A {
int num ;
public :
A(int x) {
num = x ; }
};
class B {
string name ;
A object ;
B(string n,int x) {
name = n ;
object(x) ;
}
}
int main () {
B ob("Moh",435) ;
system ("pause") ;
return 0 ; }
Explanation / Answer
#include <iostream>
using namespace std;
class A {
int num ;
public :
A(int x) {
num = x ; }
};
class B {
string name ;
public:
B(string n,int x) {
name = n ;
A object(x) ;
}
};
int main () {
B ob("Moh",435) ;
//system ("pause") ;
return 0 ; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.