If You Are From The 09 Batch Then Read This >>

This Site is created for the Bharati Vidyapeeth's BCA 09 Batch..and hence everyone from you are requested to send your email ID at abhilash238650@gmail.com..Owner will send you a request to your Email-ID and after accepting it even you can post your views, day to day experiences and class works on this blog.
Visit owner's blog at
www.bloggerabhilash.info

Tuesday, May 8, 2012

C++ PROGRAMS

Add, Int, Float, Double



#include
#include
int add (int a,int b);
float add (float a, float b, float c);
double add (double x, double y);
{
return (a+b)
}
float add (float a, float b, float c);
{
return (a+b+c)
}
double add (double x, double y);
{
return (x+y)
}
void main()
{
clrscr();
cout<
cout<
cout<
getch();
}


CALCULATE INTEREST:



#include(iostream.h)
#include(conio.h)
#include(math.h)

void main()
{
double p, r, t, i, am;
cout<< " Enter principal, rate , time ?";
cin>> p >> r >> t;

i = (p * r* t) / 100;
am = p + i;

cout<< "\n Principal Amt = Rs. " << p;
cout<< "\n Rate = " << r << "%" ;
cout << "\n Time = " << t << "yrs.";
cout<< "\n The Interest Amt = Rs. " << i ;
cout<< "\n The Total Amt = Rs. " << am;
am = pow((p* ( 1 + (r/100)), t);
i = am - p;
cout << "\n The Interest Amt = Rs. " << i;
cout<< "\n The Total Amt = Rs. " << am;


getch();
}


FIND QUOTIENT AND REMINDER ADDING 2 INTEGER:



#include

#include

int main()

{ // Code Copyright @ Coders Guide http://codersguide.org

clrscr();

int x,y,add,quotient,remainder;

cout << “Enter 2 integers: ”;

cin>>x>>y;

add= x+y;

quotient=x/y;

remainder=x-(quotient*y);

cout << “addition of ” << x << ” & ” << y << ” = ” << add << “\n”;

cout << “Quotient of ” << x << ” & ” << y << ” = ” << quotient << “\n”;

cout << “Remainder of ” <<  x << ” & ” << y << ” = ” << remainder << “\n”;

getch();

return 0;

}


FRIEND FUNCTION:


#include
#include
class Cmplx1
{
int real,imagin;
public :
void get()
{
cout<<"\n\n\t ENTER THE REAL PART : ";
cin>>real;
cout<<"\n\n\t ENTER THE IMAGINARY PART : ";
cin>>imagin;
}
friend void sum(Cmplx1,Cmplx1);
};
void sum(Cmplx1 c1,Cmplx1 c2)
{
cout<<"\n\t\tRESULT : ";
cout<<"\n\n\t["<
cout<<" ] + [ "<
cout<<" ] = "<
}
void main()
{
Cmplx1 op1,op2;
clrscr();
cout<<"\n\n\tADDITION OF TWO COMPLEX NUMBERS USING FRIEND FUNCTIONS\n\n";
cout<<"\n\tINPUT\n\n\t\t OPERAND 1";
op1.get();
cout<<"\n\n\t\t OPERAND 2";
op2.get();
sum(op1,op2);
getch();
}

FUNCTION OVERLOADING:




#include
#include
#include
#define pi 3.14
class fn
{
      public:
        void area(int);  //circle
        void area(int,int);  //rectangle
        void area(float ,int,int);  //triangle
};

void fn::area(int a)
{
      cout<<"Area of Circle:"<
}
void fn::area(int a,int b)
{
      cout<<"Area of rectangle:"<
}
void fn::area(float t,int a,int b)
{
      cout<<"Area of triangle:"<
}



void main()
{
     int ch;
     int a,b,r;
     clrscr();
     fn obj;
     cout<<"\n\t\tFunction Overloading";
     cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of Triangle\n4.Exit\n:”;
     cout<<”Enter your Choice:";
     cin>>ch;

     switch(ch)
     {
              case 1:
                cout<<"Enter Radious of the Circle:";
                cin>>r;
                obj.area(r);
                break;
              case 2:
                cout<<"Enter Sides of the Rectangle:";
                cin>>a>>b;
                obj.area(a,b);
                break;
              case 3:
                cout<<"Enter Sides of the Triangle:";
                cin>>a>>b;
                obj.area(0.5,a,b);
                break;
              case 4:
                exit(0);
     }
getch();
}




HYBRID INHERITANCE:



#include
#include
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;
}
void put_number(void)
{
cout<<"Roll No.: "< }
};
class test:public student
{
protected:
float part1, part2;
public:
void get_marks (float x, float y)
{
part1=x;
part2=y;
}
void put_marks(void)
{
cout<<"Marks obtained: \n";
cout<<"Part1="< cout<<"Part2="< }
};
class sports
{
protected:
float score;
public:
void get_score(float s)
{
score=s;
}
void put_score(void)
{
cout<<"Sports wt: "< }
};
class result : public test, public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total=part1+part2+score;
put_number();
put_marks();
put_score();
cout<<"Total Score: "<}
int main()
{
result student_1;
student_1.get_number(1234);
student_1.get_marks(27.5,33.0);
student_1.get_score(6.0);
student_1.display();
return 0;
}


INHERITANCE STUDENT CLASS:



#include
#include

using namespace std;

class Person {
public:
      Person(string name, int age) {
            this->name = name;
            this->age = age;
      }
      string getName() {
            return name;
      }
      int getAge() {
            return age;
      }
private:
      string name;
      int age;
};

class Student : public Person
{
public:
      Student(string name, int age, float grade) : Person(name, age) {
            this->grade = grade;
      }
      float getGrade() {
            return grade;
      }
private:
      float grade;
};

int main() {
      cout << "Creating a student Class..." << endl;
      Student johnDoe("XYZ", 30, 5.0);
      cout << "Student's name: " << XYZ.getName() << endl;
      cout << "Student's age: " << XYZ.getAge() << endl;
      cout << "Student's grade: " << XYZ.getGrade() << endl;

      return 0;
}


OVERLOAD STRING CLASS:



#include
#include
using namespace std;
class String
 {
  char *str;
public:
  String();
  String(const char *s);
  String(const String& s);
  void setString(const char *s);
  void setString(const String& s);
  int stringLength() const;
  char *getString() const;
  String& operator=(const String& s);
};
String::String()
{
  str = 0;
}
String::String(const char *s)
{
  str = new char[strlen(s) + 1];
  strcpy(str, s);
}
String::String(const String& s)
{
  str = new char[strlen(s.str) + 1];
  strcpy(str, s.str);
}
void String::setString(const char *s)
{
  setString(String(s));
}
void String::setString(const String& s)
{
  *this = s;
}
int String::stringLength() const
{
  return strlen(str);
}
char *String::getString() const
{
  return str;
}
String& String::operator=(const String& s)
{
  char *temp = new char[strlen(s.str) + 1];
  strcpy(temp, s.str);
  delete [] str;
  str = temp;
  return *this;
}
String operator+(const String& a, const String& b)
{
  char *temp = new char[a.stringLength() + b.stringLength() + 1];
  strcpy(temp, a.getString());
  strcat(temp, b.getString());
  return String(temp);
}
int main()
{
  String s1 = "Hello World";
  String s2;
  s2.setString("This is a string");
  cout<<"string 1 is "<< s1.stringLength() <<" characters long"<
  cout<<"string 1 is "<< s1.getString() <<'\n';
  cout<<"string 2 is "<< s2.getString() << endl <
  cout<<"assign string 2 to string 1"<
  s1.setString(s2);
  cout<<"string 1 is "<< s1.getString() <
  return 0;
}


SUM & AVERAGE of TWO INTEGERS: 


#include
#include

using namespace std;

int main (int argc, char *argv[])
{
    int num[100];
    int n;
    register int i;
    int sum = 0;
    float avg;
    cout << "Enter number of items in array: ";
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cout << "Enter the " << i+1 << "th number: ";
        cin >> num[i];
        sum += num[i];
    }
    avg = (float) sum/n;
    cout << "Sum is " << sum << "\nAnd Average = " << avg;
    getch();
}


VIRTUAL CLASS:


#include
#include
class base
{
    public:
      virtual void show()
      {
                cout<<"\n  Base class show:";
      }
      void display()
      {
              cout<<"\n  Base class display:" ;
      }
};
 
class drive:public base
{
   public:
      void display()
      {
              cout<<"\n  Drive class display:";
      }
      void show()
      {
              cout<<"\n  Drive class show:";
      }
};
 
void main()
{
   clrscr();
   base obj1;
   base *p;
   cout<<"\n\t P points to base:\n"  ;
 
   p=&obj1;
   p->display();
   p->show();
 
   cout<<"\n\n\t P points to drive:\n";
   drive obj2;
   p=&obj2;
   p->display();
   p->show();
   getch();
}





No comments:

Post a Comment

You can ask your queries here and we will try to get back to you as soon as we will be done working with that..

Note: Only a member of this blog may post a comment.

Just Type The Keyword To Search Your Answer -- >>