"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, March 23, 2010

Write a C++ program to implement a circle class. Each Object of this class will represent a circle, storing its radius and the x and y coordinate of its center as floats. Include two access functions for: (a) Calculate area of circle , (b) calculating the circumference of circle.


#include<iostream.h>
#include<conio.h>
// start class
class circle
{

private :

float radius;
float x , y;

public :

void get_radius(float r)
{ radius = r; }

void get_xycoor(float a, float b)
{ x = a;
y = b;
}

void area( )
{
cout<< "\n\n The area of the circle of radius "<< radius <<" is " << 3.14 * radius * radius ;
}

void circum()
{
cout<< "\n\n The circumference of the circle of radius "<< radius <<" is " << 2 *3.14 * radius ;
}
};
//End of class

void main()
{
circle c1;
float rad;
cout<< "\n Enter radius :";
cin >> rad;
c1.get_radius(rad);
c1.area();
c1.circum();
getch();
}

Tuesday, March 16, 2010

Write a program to accomplish the following functions specified below.

handle( a-character) returns the reversed case of the passed character or prints it twice depending upon whether you assign the return value to it or not.


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


void handle(char ch)
{
cout<< ch << " " << ch;
}

int handle(int ch)
{
if(ch > = 65 && ch < = 90) // ASCII CODE of A = 65,Z=90
  ch =ch + 32;
else
   { if(ch > = 97 && ch < = 122) // ASCII code of a=97,z=122
           ch = ch - 32;
    }
return ch;
}
     
void main()
{
cout<< "\n Enter a character :";
char c;
cin >> c;

// To print the character twice
handle(c);


cout<<"\n\n" ;

// To reverse the character
int a = handle(c);

cout<< "\n The reverse character of " < < c << "is " << (char)a;

getch();
}
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.