Write the following program in c++.
i. Create a class of your own choice with 5 attributes.
ii. Create an object of named objone in the intmain() function
iii. Access attributes and set values for all the 5 attributes
iv. Print all the attribute values
v. Create a function in the class that add two number and access the function using the oblject.
#include<iostream>
using namespace std;
class Myclass {
private:
int u=10;
int v=20;
int w=30;
int x=40;
int y=50;
public:
Myclass() : x(10), y(x + 10) {}
void print();
};
void Myclass::print()
{
cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y;
}
int add Myclass::display()
{
return x+y;
}
}
int main()
{
Myclass objone;
objone.print();
objone.display();
getchar();
return 0;
}
Comments
thank you for the assistance
Leave a comment