Powered by Blogger.

Tuesday, February 5, 2013

quadratic equations

/* Q.N 1. Write a C++ code to solve the quadratic equations . */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>

class qequ
{
      int a,b,c;
      float root1,root2;
      public:
             void getdata(int ,int ,int);
             void calroot();
             void disp();
             };
            
      void qequ::getdata(int x,int y,int z)
      {
           a=x;
           b=y;
           c=z;
           }
          
      void

main()
{
      int a,b,c;
      float d,root1,root2;
     
      cout<<"\nEnter The Value Of a , b & c from Equation : ";
      cin>>a>>b>>c;
     
      d=sqrt(b*b-4*a*c);
     
      if(d<0)
      cout<<"\nThe Roots Are Imaginarry !";
     
      else
      {
          root1=((-b+d)/2*a);
          root1=((-b+d)/2*a);
          cout<<"\nThe Roots Are : ";
          cout<<"\nRoot 1 : "<<root1;
          cout<<"\nRoot 2 : "<<root2;
          }
     
      getch();
      }

Student info

/*Create a class student with private data members name ,roll no,age and member functions input() to take input of data and display() to display the records .
Test the program for one student*/
#include<iostream.h>
#include<string.h>
#include<conio.h>

class student
{
      private:
              char name[25];
              int roll,age;
      public:
             void input(char nam[] ,int rol,int ag);
             void display(void);
             };
            
      void student::input(char nam[25],int rol,int ag)
      {
           strcpy(name,nam);
           roll=rol;
           age=ag;
           }
          
      void student::display()
      {
      cout<<"Name    : "<<name<<endl;
      cout<<"Roll No : "<<roll<<endl;
      cout<<"Age     : "<<age<<endl;
      }
     
      int main()
      {
           student st;
           char name[25];
           int roll,age;
          
           cout<<"\nEnter Name : "<<endl;
           cin>>name;
           cout<<"Enter Roll No: "<<endl;
           cin>>roll;
           cout<<"Enter Age : "<<endl;
           cin>>age;
          
           st.input(name,roll,age);
           st.display();
          
           getch();
           return 0;
           }
/*Create a class Student with six data members (Roll No., name , marks in English ,Maths and Science , total), write a program with init()
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>

class student
{
      private:
              char name[25];
              int roll;
              float eng,math,sci,total;
      public:
             void init(char [] ,int ,float ,float ,float);
             float calctotal(void);
             void display(void);
             };
            
      void student::init(char nam[25],int rol, float engl, float maths, float scie)
      {
           strcpy(name,nam);
           roll=rol;
           eng=engl;
           math=maths;
           sci=scie;
           total=calctotal();
           }
          
      void student::display()
      {
      cout<<"Name    : "<<name<<endl;
      cout<<"Roll No : "<<roll<<endl;
      cout<<"English : "<<eng<<endl;
      cout<<"Math    :  "<<math<<endl;
      cout<<"Science : "<<sci<<endl;
      cout<<"Total   : "<<total<<endl;
      }
     
      float student::calctotal()
      {
            return(eng+sci+math);
            }
          
     
      int main()
      {
           student st1,st2;
           char name[25];
           int roll;
           float eng,sci,math;
          
           cout<<"\nEnter Name : "<<endl;
           cin>>name;
           cout<<"Enter Roll No: "<<endl;
           cin>>roll;
           cout<<"\n\tEnter Marks : \n";
           cout<<"English    : "<<endl;
           cin>>eng;
           cout<<"Mathematics: "<<endl;
           cin>>math;
           cout<<"Science    : "<<endl;
           cin>>sci;
          
           st1.init(name,roll,eng,math,sci);
           st1.display();
          
           cout<<"\nEnter Name : "<<endl;
           cin>>name;
           cout<<"Enter Roll No: "<<endl;
           cin>>roll;
           cout<<"\n\tEnter Marks : \n";
           cout<<"English    : "<<endl;
           cin>>eng;
           cout<<"Mathematics: "<<endl;
           cin>>math;
           cout<<"Science    : "<<endl;
           cin>>sci;
           st2.init(name,roll,eng,math,sci);
           st2.display();
          
           getch();
           return 0;
           }

Sunday, February 3, 2013

Comparision

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


class comparison
{
      int x,y,max;
      public:
             void getdata(int a,int b);
             void largest(void);
             void print(void);
             };
            
             void comparison::getdata(int a,int b)
             {
                  x=a;
                  y=b;
                  }
            void comparison::largest()
            {
                 if(x>y)
                 max=x;
                 else
                 max=y;
                 }
           
            void comparison::print()
            {
                 cout<<"\nThe Largest Number : "<<max<<endl;
                 }
                
            int main()
            {
                comparison com;
                int a,b;
               
                cout<<"Enter Two numbers : ";
                cin>>a>>b;;
               
               
                com.getdata(a,b);
                com.largest();
                com.print();
               
                getch();
                }

Saturday, January 19, 2013

print the series....

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
clrscr();
int i;
float z;

for(i=0;i<8;i++)
{
z=pow(2,i);

//for(i=0;i<8;i++)
printf(" 1/%3.f\n",z);
}
getch();
}

Hex,Oct equivalent

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    clrscr();
    int hex;
    int oct=024;
    int un=-455;
    printf("enter the no. for hexadecimal no.");
    scanf("%d",&hex);
    printf("\nThe Hexadecimal equivalent is:%x",hex);
    printf("\nthe octal no: %o",oct);
    printf("\nthe ..... %u",un);
    getch();
    }

Print The Respective ASCII Values

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


void main()
{
clrscr();
char a;
printf("Enter the ascii character:\n");
scanf("%c",&a);
printf("%d",a);
getch();
}