Search This Blog

Pages

Monday, April 25, 2011

bg

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);

}

Saturday, January 29, 2011

LabTask1.3

--------------------
/*By Subodh Dahal*/

--------------------


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

int main()
{
int roll[5],age[5];
char name[5][20],check;
int i=0;

Wednesday, January 26, 2011

LabTask1.2

/*WAP to find smallest and largest number from array using DMA with new and delete operator. After destroying its memory with delete operator what will happen? Comment on your results.*/

#include<iostream.h>
int main()
{
int *p=new int[20];

Friday, January 21, 2011

Initial of Lab Task 1

----------------------------------------------------------
Written by Sagar Giri

----------------------------------------------------------


OBJECT: BASIC PROGRAMMING ON C++

THEORY:

Output operator
cout<<

            The identifier cout is a predefined object that represents the standard output stream in C++. The operator << is called the insertion or put to operator. In inserts (or sends) the contents of the variable on its right to the object on its left. If string represents a string variable then the following statement will display its contents.

            cout<<string;

E.g.:

Monday, January 17, 2011

LabTask1.1

#include<iostream.h>
int main()
{
float fahrenheit, celcius;
cout<<"Please input the temperature in Fahrenheit: ";
cin>>fahrenheit;
celcius=5/9*(fahrenheit-32);
cout<<"\nThe temperature in Celcius is: "<<celcius;
return 0;
}

Wednesday, January 12, 2011

Storing numbers dynamically n displaying them


/*
 * storing_numbers_dynamically_n_displaying_them.cpp
 *
 *  Created on: Jan 12, 2011
 *      Author: bgsudeep
 *      
 *      Here "dynamically" means a pointer with delete option
 *      We should have to store the numbers using a pointer in main function and at the end of the
 *      program we should have to clean or delete the memory used by the program.
 */

#include<iostream.h>
int main()
{
int *p=new int[10];
int i;

Swapping Two Values using call by reference


/*
 * swapping_values_using_call_by_reference.cpp
 *
 *  Created on: Jan 12, 2011
 *      Author: bgsudeep
 */

#include<iostream.h>
void swap(int &, int &);
int main()
{
int a, b;
cout<<"Please input two numbers separated by space or an enter key: "<<endl;
cin>>a>>b;
swap(a,b);
cout<<"Your swapped number is: "<<endl<<a<<" and "<<b;
return 0;
}
void swap(int &pa, int &pb)
{
int temp;
temp=pa;
pa=pb;
pb=temp;
}

Return by Reference

/*
* Return_by_reference.cpp
*
* Created on: Jan 12, 2011
* Author: bgsudeep
* This program is suitable when we need to give some value for the greater value among two values.
*/

#include<iostream.h>
int &max(int &a, int &b);
int main()
{
int x,y;
cout<<"Please input two numbers: "<<endl;
cin>>x>>y;
max(x,y)=10;
cout<<"x= "<<x; //Here if you put the value of x which is less than y then it will displays the value of x.
//If you put the value of x which is greater than y then it will displays the value 10.

return 0;
}
int &max(int &a, int &b)
{
if (a>b)
return a;
else
return b;
}

Tuesday, January 11, 2011

Review of C

For this program, credit goes to my friend Suroj Karmacharya (SKAMMA)
/*Write a program that removes all the extra spaces, tables or any other wild or special characters from a given sentence and make a simple English sentence ended with (.).
* Example: Input: I like $^ C++ very much
* Output: I like C++ very much.*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{