Hello Peeps,
I just moved to United Kingdom last week, and I continuously want this learning rhythm to go. As I'm also learning OOPs concepts, this quarantine period helped me with little bit of programming. Click here to know the concepts I learnt so far in C++.
#include <iostream> class army // Class declaration { public: // Access Specifiers int number_suffix; //Member Variable string key; void enrollment(string name, int age) {key = name; number_suffix = age;} void retirement() // Member Functions {cout << key << " is retiring";} } int main() { army a1; // Object creation and Memory allocation a1.enrollment("Shirley", 31); a1.retirement(); return 0; }
The declaration of a class doesn't have a ; at the end, so it threw an error as 'new types may not be defined in a return type'
#include <iostream> class army // Class declaration { public: // Access Specifiers int number_suffix; //Member Variable string key; void enrollment(string name, int age) {key = name; number_suffix = age;} void retirement() // Member Functions {cout << key << " is retiring";} }; int main() { army a1; // Object creation and Memory allocation a1.enrollment("Shirley", 31); a1.retirement(); return 0; }
In the above program, I haven't used 'using namespace std;', but still it worked. I'm not sure of the use of 'namespace std'.
That's all guys!! Bye Bye...
Comments
Post a Comment