0% found this document useful (0 votes)
105 views8 pages

C++ Assignment-3

The document contains 4 C++ programs: 1. A program using inline functions to find the minimum and maximum of two numbers. 2. A program creating a Student class with a friend function to display student details. 3. A program using a parameterized constructor to check if a number is prime. 4. A program creating a Bank class using a copy constructor to demonstrate bank transactions.

Uploaded by

Kavibharath R
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)
105 views8 pages

C++ Assignment-3

The document contains 4 C++ programs: 1. A program using inline functions to find the minimum and maximum of two numbers. 2. A program creating a Student class with a friend function to display student details. 3. A program using a parameterized constructor to check if a number is prime. 4. A program creating a Bank class using a copy constructor to demonstrate bank transactions.

Uploaded by

Kavibharath R
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/ 8

C++ ASSIGNMENT

1. C++ program using inline functions for finding minimum and maximum
of two elements.
#include<iostream>
using namespace std;
class number
{
private:
int x,y;
public:
inline int min(int x, int y)
{
cout<<"Enter the value of x: ";
cin>>x;
cout<<"Enter the value of y: ";
cin>>y;
return (x>y)?x;y;
cout << "Minimum of " << x << " and " << y << " is ";
}
inline int max(int x, int y)
{
cout<<"Enter the value of x: ";
cin>>x;
cout<<"Enter the value of y: ";
cin>>y;
return (x<y)?x:y;

R.KAVIBHARATH 1901102 CSE-B


cout << "Maximum of " << x << " and " << y << " is ";
}
};
int main()
{
number n;
n.min(x,y);
n.max(x,y);
return 0;
}
Output:
Enter the value of x: 15
Enter the value of y: 6
Minimum of x and y is 6
Enter the value of x: 15
Enter the value of y: 6
Maximum of x and y is 15

R.KAVIBHARATH 1901102 CSE-B


2. C++ program to create a class called student. Create a friend function
called display to display the student details.
#include<iostream>
using namespace std;
class student
{
char name[20],branch[10];
int sem,regno;
friend void input();
friend void display();
};
void input()
{
cout<<"Enter Name:";
cin>>name;
cout<<"Enter Reg.no.:";
cin>>regno;
cout<<"Enter Branch:";
cin>>branch;
cout<<"Enter Sem:";
cin>>sem;
}
void display()
{
cout<<"\nName:"<<name<<endl;
cout<<"\nReg.no.:"<<regno<<endl;
cout<<"\nBranch:"<<branch<<endl;
cout<<"\nSem:"<<sem<<endl;

R.KAVIBHARATH 1901102 CSE-B


}
int main()
{
student s;
s.input();
s.display();
return 0;
}
Output:
Enter Name: Kavibharath
Enter Reg.no: 1901102
Enter Branch: CSE
Enter Sem: 3
Name: Kavibharath
Reg.no: 1901102
Branch: CSE
Sem:3

R.KAVIBHARATH 1901102 CSE-B


3. C++ program using parameterized constructor for finding whether a
number is prime number or not.
#include<iostream>
using namespace std;
class prime
{
int a,k,i;
public:
prime(int x)
{
a=x;
}
void calculate()
{
k=1;
for(i=2;i<=a/2;i++)
{
if(a%i==0)
{
k=0;
break;
}
else
{
k=1;
}
}
}

R.KAVIBHARATH 1901102 CSE-B


void show()
{
if(k==1)
cout<< "\nThe Number is prime Number.\n";
else
cout<<"\nThe Number is Not prime.\n";
}
};
int main()
{
int a;
cout<<"\nEnter any Number: ";
cin>>a;
prime obj(a);
obj.calculate();
obj.show();
return 0;
}
Output:
Enter any number: 17
The Number is prime number.

R.KAVIBHARATH 1901102 CSE-B


4. C++program to create the bank transactions using copy constructor.
#include<iostream>
using namespace std;
class bank
{
public:
int accno;
string name;
int cash;
bank(int i,string n,int k)
{
accno=i;
name=n;
cash=k;
}
bank(const bank &b)
{
accno= b.accno;
name= b.name;
cash= b.cash;
}
void display()
{
cout<<"Account number is: "<<accno<<endl;
cout<<"Name is: "<<name<<endl;
cout<<"Cash deposited is: "<<cash<<endl;
}

R.KAVIBHARATH 1901102 CSE-B


};
int main()
{
bank b1(123456, "Kavibharath",15000);
bank b2=b1;
b2.display();
return 0;
}
Output:
Account number is: 123456
Name is: Kavibharath
Cash deposited: 15000

R.KAVIBHARATH 1901102 CSE-B

You might also like