Oops 5
Oops 5
Oops 5
Write a C++ program with a class name getset. Keep a and b as private data members and
write the following functions in public mode.
i. void getdata() - Reads a and b values from the user and display the values
ii. void setdata(int,int) - Modify the values of private fields by assigning different set of numbers to
the private fields
Note: Place the functions getdata and setdata outside the class and display inside the class
#include<iostream>
class getset{
int a,b;
public:
void getdata();
void display(){
};
void getset::getdata(){
cout<<"enter 2 values";
cin>>a>>b;
display();
b=d;
int main(){
getset obj;
obj.getdata();
obj.setdata(10,12);
obj.display();
b. Write a C++ program with a class name student. Keep roll number and name as private
data members and write the following functions in public mode.
i. void setdata(int srn, string sname) - Assigns values directly from the main function
#include<iostream>
class student{
int roll;
string name;
public:
roll=srn;
name=sname;
void putdata(){
cout<<"The roll number of the student is "<<roll<<endl;
};
int main(){
int r;
string s;
cout<<"enter name"<<endl;
cin>>r>>s;
student obj;
obj.setdata(r,s);
obj.putdata();
c. Create a class named line and declare a constructor and destructor. The definitions are to
kept outside with a simple message in it. Keep the member functions as follows.
Note: Place all member functions, constructor and destructor definitions outside the class.
#include<iostream>
class line{
double l;
public:
line();
double getlength();
~line();
};
line::line(){
cout<<"inside constructor"<<endl;
l=len;
double line::getlength(){
return l;
line::~line(){
cout<<"inside destructor"<<endl;
int main(){
double length;
cout<<"enter length"<<endl;
cin>>length;
line obj;
obj.setlength(length);
d. Perform all operations like dot and cross product in a Vector class.
V = Xi + Yj + Zk Where, X, Y and Z are the magnitude of the vector V in the directions i , j and k
respectively.
#include<iostream>
class vector{
int a1,b1,c1,a2,b2,c2;
public:
vector(){
};
a1=a;
b1=b;
c1=c;
a2=d;
b2=e;
c2=f;
void dot(){
int dot;
dot=a1*a2+b1*b2+c1*c2;
void cross(){
int i=b1*c2-c1*b2;
int j=a1*c2-c1*a2;
int k=a1*b2-a2*b1;
cout<<i<<"i + "<<j<<"j + "<<k<<"k "<<endl;
};
int main(){
int u,v,w,x,y,z;
cout<<"enter a1,b1,c1"<<endl;
cin>>u>>v>>w;
cout<<"enter a2,b2,c2"<<endl;
cin>>x>>y>>z;
vector obj(u,v,w,x,y,z);
obj.dot();
obj.cross();
5. Write a class named as bank. Include the member variables as depositor name, account
number, balance amount. Write appropriate member functions to assign initial values, deposit
an amount and display name & balance amount. Transfer amount from one account to another
and show the balance amount available in both accounts.
include<iostream>
class bank{
string name;
int acct;
int amt;
public:
name=n;
acct=acctno;
amt=balamt;
amt+=dep;
void display(){
ob.amt+=trans;
};
int main(){
bank obj("soniya",101,300);
obj.deposit(30);
obj.display();
bank obj1("Rahul",102,400);
obj.deposit(10);