0% found this document useful (0 votes)
23 views

C++ Assignment Solution-2

Uploaded by

cookieswarna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

C++ Assignment Solution-2

Uploaded by

cookieswarna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

//Problem-2.

1:
#include<iostream>
using namespace std;
class array
{
private:
int a[10],i,n,j,temp;
public:
void input()
{
cout<<"enter number of element in array"<<endl;
cin>>n;
cout<<"Enter array elements"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void sortelement()
{
for(i = 0; i<n; i++)
{
for(j = i+1; j<n; j++)
{
if(a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void print()
{
cout<<"Sorted Array is="<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}

}
};
int main()
{
array y;
y.input();
y.sortelement();
y.print();
}
//Problem-2.2:
#include<iostream>
using namespace std;
class books
{
char title [30];
float price ;
public:
void getdata ();
void putdata ();
} ;
void books :: getdata ()
{
cout<<"Title:";
cin>>title;
cout<<"Price:";
cin>>price;
}
void books :: putdata ()
{
cout<<"Title:"<<title<< "\n";
cout<<"Price:"<<price<< "\n";
}
int main()
{

books book[3] ;
int n=3;
for(int i=0;i<n;i++)
{
cout<<"Enter details of book "<<(i+1)<<"\n";
book[i].getdata();
}
for(int i=0;i<n;i++)
{
cout<<"\nBook "<<(i+1)<<"\n";
book[i].putdata() ;
}
return 0;
}
//Problem-2.3:
#include <iostream>
using namespace std;
class Employee
{
public:
int id;//data member (also instance variable)
string name;//data member(also instance variable)
float salary;
void insert(int i, string n, float s)
{
id = i;
name = n;
salary = s;
}
void display()
{
cout<<id<<" "<<name<<" "<<salary<<endl;
}
};
int main()
{
Employee e1; //creating an object of Employee
Employee e2; //creating an object of Employee
e1.insert(201, "Manab Das",25000);
e2.insert(202, "Saikat mondal", 29000);
e1.display();
e2.display();
return 0;
}
//Problem-2.4

#include<iostream>
using namespace std;
class item
{
char item_name [30];
int item_code;
float price ;
int qty;
public:
void getdata ();
void putdata ();
};
void item :: getdata ()
{
cout<<"Enter Name of Item:";
cin>>item_name;
cout<<"Enter Item Code:";
cin>>item_code;
cout<<"Enter Item Price:";
cin>>price;
cout<<"Enter Quantity of Item:";
cin>>qty;
}
void item :: putdata ()
{
cout<<"Item Name:"<<item_name<< "\n";
cout<<"Item Code:"<<item_code<< "\n";
cout<<"Item Price:"<<price<< "\n";
cout<<"Qty of Item:"<<qty<< "\n";
}
int main()
{

item product[2] ;
int n=2;
for(int i=0;i<n;i++)
{
cout<<"Enter details of Item "<<(i+1)<<"\n";
product[i].getdata();
}
for(int i=0;i<n;i++)
{
cout<<"\nBook "<<(i+1)<<"\n";
product[i].putdata() ;
}
return 0;
}
//Problem-2.5
#include<iostream>
using namespace std;
class array
{
private:
int a[10]={7, 5, 4, 8, 9, 11,-5, 0, 2, 1};
int max,min,i,n;
public:
void maximum()
{
max=a[0];
for(i=1;i<10;i++)
{

if(a[i]>max)
{
max=a[i];
}
}
}
void minimum()
{
min=a[0];
for(i=1;i<10;i++)
{
if(a[i]<min)
{
min=a[i];
}
}
}
void print()
{
cout<<"Array is="<<endl;
for(i=0;i<10;i++)
{
cout<<a[i]<<endl;
}
cout<<"Maximum no is= "<<max<<endl;
cout<<"Minimum no is= "<<min;
}
};
int main()
{
array y;
y.maximum();
y.minimum();
y.print();
}

You might also like