Search This Blog

Pages

Sunday, February 20, 2011

LabTask 4B.3

/*By Sailesh Dhoju*/

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

class concat
{
private:
int a,b;
char str[100];

public:
concat()
{
str[100]='\0';a=0;b=0;
}

concat(char *arr)
{
strcpy(str,arr);
}
void add(concat A,concat B)
{
a=strlen(A.str);
b=strlen(B.str);

for(int i=0;i<a;i++)
str[i]=A.str[i];
for(int j=a;j<(a+b);j++)
str[j]=B.str[j-a];
str[j]='\0';
}
void display()
{
cout<<str;
}
};

int main()
{
clrscr();
concat C;
concat A("This is just"),B(" an example.");
C.add(A,B);
C.display();
getch();
return (0);

}

LabTask 4B.2

/*By Sailesh Dhoju*/

#include<iostream.h>
#include<conio.h>

class total
{
int no_pax;
float tra_rate,discount,amount;

public:
total()
{
no_pax=0;
tra_rate=0;
discount=0;
amount=0;
}

total(int a,float b)
{
no_pax=a;
tra_rate=b;
}

void calculate()
{
if (no_pax>10)
discount=0.10*tra_rate*no_pax;
amount=tra_rate*no_pax-discount;
}

total(total & x)
{
no_pax=x.no_pax;
tra_rate=x.tra_rate;
discount=x.discount;
amount=x.amount;
}

void display()
{
cout<<endl<<"the total amount:"<<amount<<endl;
}
~total(){cout<<endl<<"DESTROYED"<<endl;}

};

int main()
{
clrscr();
total t1(2,10),t2(11,10);
t1.calculate();
cout<<"1st object";
t1.display();
t2.calculate();
cout<<endl<<"2nd object";
t2.display();
total t3=t2;
cout<<endl<<"Copy of 2nd object to 3rd object ";
t3.display();
getch();
return(0);
}

LabTask 4B.1

/*Write a program that display the total time in 24-hour clock format having fixed time 12:34:56 and 10:35:14. One constructor should initialize member data hour, minute and second to 0 and another should initialize it to fixed values. Other two member functions should add two objects of type time passed as arguments and display the result.*/

/*By Sailesh Dhoju*/

#include<iostream.h>
#include<conio.h>

class time
{
 private:
 int hr,min,sec;

 public:
 time ()
 {
  hr=0;
  min=0;
  sec=0;
 }

 time (int a,int b,int c)
 {
  hr=a;
  min=b;
  sec=c;
 }

 void sum(time t1,time t2)
 {
  hr=t1.hr+t2.hr;
  min=t1.min+t2.min;
  sec=t1.sec+t2.sec;

  min=min+sec/60;
  hr=hr+min/60;
  hr=hr%24;
  min=min%60;
  sec=sec%60;
 }

 void display()
 {
 cout<<hr<<":"<<min<<":"<<sec<<endl;
 }
 ~time(){cout<<endl<<"DESTROYED"<<endl;}
};

int main()
{
 clrscr();
 time t1(12,34,56),t2(10,35,14),t3;
 t1.display();
 t2.display();
 t3.sum(t1,t2);
 t3.display();
 getch();
 return(0);
}

Tuesday, February 15, 2011

Tests

#include<iostream.h>
#include<conio.h>
#include<string.h>
const int SIZE=40;
class String
{
private:
char str [SIZE];
public:
String ()
{
strcpy (str," ");
}
String (char ch [])
{
strcpy (str, ch);
}
void getString ()
{
cout<< "Enter the string: -";
cin.get (str, SIZE);
}
int operator == (String s)
{
if (strcmp (str, s.str)==0)
return 1;
else
return 0;
}
};
void main ()
{
clrscr ();
String s1, s2, s3;
s1="bgsudeep";
s2="ACEM";
s3.getString ();
if (s3==s1)
cout<< "1st and 3rd string are same.";
else if (s2==s3)
cout<< "2nd and 3rd string are same.";
else
cout<< "All strings are unique.";
getch ();
}

Sunday, February 13, 2011

LabTask 3.b.4

/*Write a program to make a specific function of a class a friend of other class to add elements from the two classes. Both of these classes should have two integer members. Make others global functions to subtract and multiply objects of class one and class two.
By Sandesh Hetfield Shakya
*/

#include<iostream.h>
#include <conio.h>

class add2;

class add1
{
int element;

public:
add1(int x)
{
element=x;
}

int getele()
{
return element;
}

friend int sum(add1,add2);
};

class add2
{
int element;
public:
add2(int y)
{
element=y;
}
int getele()
{
return element;
}

friend int sum(add1,add2);
};

int sum(add1 A, add2 B)
{
return (A.element+B.element);
}
int sub(add1 A, add2 B)
{
return(A.getele()-B.getele());
}
int mul(add1 A,add2 B)
{
return(A.getele()*B.getele());
}


int main ()
{
clrscr();
add1 a(5);
add2 b(7);

cout<<endl<<"sum of add1 & add2 is :"<<sum(a,b);
cout<<endl<<"subtraction: "<<sub(a,b);
cout<<endl<<"multiplication:"<<mul(a,b);
getch();
return (0);
}

Friday, February 4, 2011

LabTask3.a.4

----------------
By Raj Kumar Shah
----------------

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class array
{
private:
int *arr,counter,size;
public:
void initialize(int x)
{
size=x;
counter=0;
arr=new int[x];
}
void add(int a)
{
arr[counter]=a;
counter++;

}
void remove(int pos)
{
for(int i=pos+1;i<counter;i++)
{
arr[i-1]=arr[i];
}
counter--;
}
void get(int pos)
{
cout<<"on your request:"<<endl<<arr[pos];


}
void assign(int data,int pos)
{
arr[pos]=data;
}
void display()
{
for(int i=0;i<counter;i++)
cout<<arr[i];
}

};
int main()
{
array A;
int choice,data,x,a;

while(1)
{
cout<<endl<<"1.add";
cout<<endl<<"2.remove";
cout<<endl<<"3.get";
cout<<endl<<"4.assign";
cout<<endl<<"5.display";
cout<<endl<<"6.exit";
cout<<endl<<"enter your choice:";
cin>>choice;

switch(choice)
{
case 1:
cout<<"enter the no of data :";
cin>>x;
A.initialize(x);
for(int i=0;i<x;i++)
{ cout<<"enter data:";
cin>>a;
A.add(a);
}
break;
case 2:
cout<<"enter position of data to be removed:";
cin>>x;
A.remove(x);
break;
case 3:
cout<<"enter position to be displaced:";
cin>>x;
A.get(x);
break;
case 4:

cout<<"enter data to be assigned :";
cin>>data;
cout<<"enter its position:";
cin>>x;
A.assign(data,x);
break;
case 5:
A.display();
break;
case 6:
exit(0);

}
}
getch();
return(0);

}

LabTask3.a.3

#include<iostream.h>

#include<conio.h>

class count

{

private:

 

static int sum;

public:

void getdata()

{

 

sum++;

}

void display()

{

cout<<endl<<"sum="<<sum;

 

 

}

static void show_sum()

{

cout<<endl<<"sum="<<sum;

 

}

 

};

int count :: sum;

int main()

{

count A,B,C;

cout<<endl<<"initial value of static data:";

A.display();

B.display();

C.display();

A.getdata();

B.getdata();

C.getdata();

 

cout<<endl<<"final value of static data:";

A.display();

B.display();

C.display();

cout<<endl<<"static function:"<<endl;

A.show_sum();

B.show_sum();

C.show_sum();

getch();

}

LabTask3.2

#include<iostream.h>

#include<conio.h>

class f2c

{

private:

float c,f;

public:

void getdata(float x)

{

f=x;

c=0;

}

void convert()

{

c=(f-32)*100/180;

 

}

void display()

{

cout<<"celsius is:"<<c;

 

}

 

};

class c2f

{

private:

float c,f;

public:

void getdata(float x)

{

c=x;

f=0;

}

void convert()

{

f=(c)*180/100;

 

}

void display()

{

cout<<"cfarenheit is:"<<f;

 

}

 

};

int main()

{

cout<<"1.conversion of farenfeit to celsuis:"<<endl;

cout<<"2.conversion of celsius to farenheit:"<<endl;

int choice;

cout<<"enter your choice:"<<endl;

cin>>choice;

switch(choice)

{

case 1:

f2c A;

float x;

cout<<"enter farenheit:"<<endl;

cin>>x;

A.getdata(x);

A.convert();

A.display();

break;

case 2:

c2f B;

float y;

cout<<"enter celsius:"<<endl;

cin>>y;

B.getdata(y);

B.convert();

B.display();

break;

default:

cout<<endl<<"wrong entry:";

break;

};

getch();

return(0);

}

LabTask3.1

#include<iostream.h>
#include<conio.h>

class degree
{
private:
float d,r;
public:
void getdata(float x)
{
d=x;
r=0;
}
void convert()
{
r=d*180/3.1415;

}
void display()
{

cout<<r<<"radian ="<<d<<"degree";
}
};

int main()
{

degree A;
float x;
cout<<"enter degree :";
cin>>x;
A.getdata(x);
A.convert();
A.display();

getch();
return(0);

}