You are on page 1of 10

#include <iostream.

h>
#include <conio.h>

double power(double m,int n=2)


{
double pow=1;
for(int i=1;i<=n;i++)
{
pow=pow*m;
}
return(pow);
}

void main()
{
clrscr();
double m,result;
int n,ch;
cout<<"\n\n\nCHOICES\n\n";
cout<<"1.Only Value of M\n";
cout<<"2.Value for both M and N\n";
cout<<"ENTER YOUR CHOICE:-";
cin>>ch;
cout<<endl<<endl;
switch(ch)
{
case 1 : cout<<"Enter Value for M:-";
cin>>m;
result=power(m);
cout<<"Power function when default argument is used ="<<result;
break;
case 2 : cout<<"Enter Value for M and N:-";
cin>>m>>n;
result=power(m,n);
cout<<"Power function when actual argument is use ="<<result;
break;
default: cout<<"Entered Value is Invalid, Try again";
}
getch();
}
}#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#define n 100

class vector
{
int size;
int coord[n];
public:
vector();
void modify();
void multiply();
void display();
};
vector::vector()
{
cout<<"\n Enter Number of Co-ordinates : ";
cin>>size;
if(size>100)
{
cout<<"Invalid number of Co-ordinates";
}
else
{
cout<<"\n Enter " << size << " Co-ordinates : ";
for(int i=0; i<size; i++)
{
cin>>coord[i];
cout<<" ";
}
}
}
void vector::modify()
{
cout<<endl<<"\n Enter " << size << " New Co-ordinates : ";
for(int i=0; i<size; i++)
{
cout<<" ";
cin>>coord[i];
}
}
void vector::multiply()
{
int num;
cout<<endl<<"\n Enter Number to Multiply : ";
cin>>num;
for(int i=0; i<size; i++)
{
coord[i]=coord[i]*num;
}
}
void vector::display()
{
cout<<"\n Vector : (";
for(int i=0; i<size; i++)
{
cout<<coord[i];
if(i!=size-1)
cout<<",";
}
cout<<")";
}
int main()
{ clrscr();
vector v;
v.display();
cout<<"\n Modifying values";
v.modify();
v.display();
cout<<"\n Multiplying with scalar";
v.multiply();
v.display();
getch();
return 0;
}
#include <iostream.h>
#include <string.h>
#include<conio.h>
#include<stdio.h>
class String
{
char*str;
int length;
public:
String()
{
length=0;
str=new char[length+1];
}
String(char*x)
{
length=strlen(x);
str= new char[length+1];
strcpy(str, x);
}
void concat(String &x,String &y)
{
length=x.length +y.length;
delete str;
str=new char[length+1];
strcpy(str,x.str);
strcat(str, y.str);
}
void disp()
{
cout<<"\nlength is: "<<length;
cout<<"\nstring is: "<<str;
}
};
void main()
{
clrscr();
char s1[30],s2[40];
char s3[]={"Well done!"};
cout<<"Enter String 1: ";
gets(s1);
cout<<"Enter String 2: ";
gets(s2);
String s(s1),t(s2),u,v(s3);
u.concat(s,t);
u.disp();
v.disp();
getch();
}
#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

class stock

char author[50];

char title[50];

char pub[50];

double price;

int numcopies;

public:

stock();

int access_title(char a[]);

void input();

void getdata(int);

};

stock::stock()

char author[50]={"abc"};

char title[50]={"efg"};

char pub[50]={"hij"};

price=500;

numcopies=50;

int stock::access_title(char a[])

if(strcmp(title,a))

return 0;

else return 1;
}

void stock::getdata(int num)

if(numcopies>=num)

cout<<"\nCost of "<<num<<" books is Rs. "<<(price*num);

else

cout<<"\nSorry! These many copies are unavailable!";

void stock::input()

cout<<"\nTitle: ";

gets(title);

cout<<"\nAuthor:";

gets(author);

cout<<"\nPublisher:";

gets(pub);

cout<<"\nPrices:";

cin>>price;

cout<<"\ncopies available:";

cin>>numcopies;

void main()

clrscr();

stock obj[2];

int n;

char ttle[50];

cout<<"Enter details of 3 books";


for(int i=0;i<2;++i)

obj[i].input();

cout<<endl;

cout<<"\n Enter title of required book\n";

gets(ttle);

for(i=0;i<2;i++)

if(obj[i].access_title(ttle))

cout<<"\nHow many copies? ";

cin>>n;

obj[i].getdata(n);

else

cout<<"\nBook unavailable";

getch();

}
#include<iostream.h>

#include<conio.h>

class FLOAT

float no;

public:

FLOAT(){}

void getdata()

cout<<"\n ENTER AN FLOATING NUMBER :";

cin>>no;

void putdata()

cout<<"\n\nANSWER IS :"<<no;

FLOAT operator+(FLOAT);

FLOAT operator*(FLOAT);

FLOAT operator-(FLOAT);

FLOAT operator/(FLOAT);

};

FLOAT FLOAT::operator+(FLOAT a)

FLOAT temp;

temp.no=no+a.no;

return temp;

FLOAT FLOAT::operator*(FLOAT b)

FLOAT temp;
temp.no=no*b.no;

return temp;

FLOAT FLOAT::operator-(FLOAT b)

FLOAT temp;

temp.no=no-b.no;

return temp;

FLOAT FLOAT::operator/(FLOAT b)

FLOAT temp;

temp.no=no/b.no;

return temp;

void main()

clrscr();

FLOAT a,b,c;

a.getdata();

b.getdata();

c=a+b;

cout<<"\n\nAFTER ADDITION OF TWO OBJECTS";

c.putdata();

cout<<"\n\nAFTER MULTIPLICATION OF TWO OBJECTS";

c=a*b;

c.putdata();

cout<<"\n\nAFTER SUBSTRACTION OF TWO OBJECTS";


c=a-b;

c.putdata();

cout<<"\n\nAFTER DIVISION OF TWO OBJECTS";

c=a/b;

c.putdata();

getch();

You might also like