C++ Basic

What is C++?
  1. C++ is an object oriented programming language. It was developed by Bjarne Stroustrup at AT & T Bell Laboratories in Murray Hill Jersey, USA, in the early 1980's.
  2. C++ is an augmented(incremented) version of C.
  3. C++ is a superset of C.
  4. The most important features that c++ adds on to C are classesinheritance,polymorphismfunction overloading and operator overloading.
Applications of C++

C++ is a versatile language for handling very large programs. It is suitable for virtually any programming task including development of editors, compilers,databases, communication systems and any complex real life application systems.


Questions and answer of Program

/*
   1.  Write a Program to read two numbers from the keyboard and display the larger value on the
*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b;
    cout<<"Enter first number"<<endl;
    cin>>a;
    cout<<"Enter second number"<<endl;
    cin>>b;

    if(a>=b)
    cout<<"Larger value is "<<a;
    else
    cout<<"Larger value is "<<b;
    getch();





/*
   2. Write a Program to input an integer value from keyboard and display on screen
    "WELL DONE" that many times.
*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int n;
    cout<<"Enter how many times"<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
        cout<<"WELL DONE"<<endl;
    getch();
}

/*
3. Write a Program to display the following output using a single cout statement.
        Maths=90
        Physics=77
        Chemistry=69

*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int Maths=90,Physics=77,Chemistry=69;
    cout<<"Maths= "<<Maths<<endl
        <<"Physics= "<<Physics<<endl
        <<"Chemistry= "<<Chemistry;
    getch();



}


/*
    4. Write a Program that ask  for a
    temperature in Fahrenheit and display it in Celsius.
*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float f,c;
    cout<<"Enter temperature in Fahrenheit"<<endl;
    cin>>f;
    c=(5*(f-32))/9;
    cout<<"Fahrenheit="<<f<<"\nCentrigrade="<<c;
    getch();
}


/*
    5. Write a Program to read the values of a,b and c
    and display the value of x, where

     x=a/b-c

    Test your program for the following values:

    (a) a=250,b=85,c=25
    (b)a=300,b=70,c=70
*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a=250,b=85,c=25;
    int x;
    x=a/(b-c);
    if((b-c)!=0)
        cout<<"x= "<<x;
    else
        cout<<"Divide by zero occur";

    a=300;
    b=70;
    c=70;
    x=a/(b-c);
    if((b-c)!=0)
        cout<<"x= "<<x;
    else if((b-c)==0)
        cout<<"Divide by zero occur";


    getch();

/*
    6. Write a Program that ask  for a
    temperature in Fahrenheit and display it in Celsius using a class called temp and member functions.
*/
#include<iostream.h>
#include<conio.h>
class temp
{
    float f;
    public:
        void readData(void);
        float getData(void);
};
inline void temp::readData(void)
{
    cout<<"Enter temperature in Fahrenheit"<<endl;
    cin>>f;
}
inline float temp::getData(void)
{
    return (5*(f-32))/9;

}

void main()
{
    clrscr();
    temp t;
    t.readData();
    cout<<"The temperature in Celsius is "<<t.getData();
    getch();
}

Comments

Popular posts from this blog

Cyber Security And Ethical Hacking Free Webinar With Certification