fork download
  1. #include<iostream>
  2.  
  3. class Student
  4. {
  5. private:
  6. char name[50];
  7. int stunum;
  8. public:
  9. Student(char *n,int sn=12345);
  10. void setstunum(int sn);
  11. int getstunum();
  12. void Student::setname(char *n);
  13. char *Student::getname();
  14. ~Student();
  15. };
  16.  
  17. Student::Student(char *n,int sn)
  18. {
  19. strcpy(name,n);
  20. stunum = sn;
  21. }
  22.  
  23. void Student::setstunum(int sn)
  24. {
  25. stunum = sn;
  26. }
  27.  
  28. int Student::getstunum()
  29. {
  30. return stunum;
  31. }
  32.  
  33. void Student::setname(char *n)
  34. {
  35. strcpy(name,n);
  36. }
  37.  
  38. char *Student::getname()
  39. {
  40. return name;
  41. }
  42.  
  43. Student::~Student()
  44. {
  45. cout << "Object has been destroyed" << endl;
  46. }
  47.  
  48. int main()
  49. {
  50. Student stu1("John",10000);
  51. Student stu2("Mary");
  52. stu1.setstunum(50000);
  53. cout << stu1.getstunum() << endl;
  54. cout << stu1.getname() << endl;
  55. cout << stu2.getstunum() << endl;
  56. cout << stu2.getname() << endl;
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:19: error: iostream: No such file or directory
prog.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Student’
cc1: warnings being treated as errors
prog.c:15: error: ISO C does not allow extra ‘;’ outside of a function
prog.c:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
prog.c: In function ‘main’:
prog.c:50: error: ‘Student’ undeclared (first use in this function)
prog.c:50: error: (Each undeclared identifier is reported only once
prog.c:50: error: for each function it appears in.)
prog.c:50: error: expected ‘;’ before ‘stu1’
prog.c:51: error: expected ‘;’ before ‘stu2’
prog.c:52: error: ‘stu1’ undeclared (first use in this function)
prog.c:53: error: ‘cout’ undeclared (first use in this function)
prog.c:53: error: ‘endl’ undeclared (first use in this function)
prog.c:55: error: ‘stu2’ undeclared (first use in this function)
stdout
Standard output is empty