Answer to Question #282909 in C++ for HAM

Question #282909

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.


1
Expert's answer
2021-12-27T08:50:02-0500
#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;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

HAM
27.12.21, 16:15

thank you for the assistance

Leave a comment