Home | | Computer Science 11th std | Example Basic C++ Programs

Chapter: 11th Computer Science : Chapter 9 : Introduction to C++

Example Basic C++ Programs

1. C++ Program to find the total marks of three subjects 2. C++ program to find the area of a circle 3. point out the errors in the following program 4. point out the type of error in the following program

Hands on practice:

 

•  Type the following C++ Programs in Dev C++ IDE and execute. if compiler shows any errors, try to rectify it and execute again and again till you get the expected result.

 

1. C++ Program to find the total marks of three subjects

 

#include <iostream>

using namespace std;

int main()

{

      int m1, m2, m3, sum;

      cout << "\n Enter Mark 1: ";

      cin >> m1;

      cout << "\n Enter Mark 2: ";

      cin >> m2;

      cout << "\n Enter Mark 3: ";

      cin >> m3;

      sum = m1 + m2 + m3;

      cout << "\n The sum = " << sum;

}

Make changes in the above code to get the average of all the given marks.

 

2. C++ program to find the area of a circle

 

#include <iostream>

using namespace std;

int main()

{

      int radius;

      float area;

      cout << "\n Enter Radius: ";

      cin >> radius;

      area = 3.14 * radius * radius;

      cout << "\n The area of circle = " << area;

}

 

3. point out the errors in the following program:

#include <iostream>

Using namespace std;

int main( )

{

      cout << “Enter a value ”;

     cin << num1 >> num2

      num+num2=sum;

      cout >> “\n The Sum= ” >> sum;

}

 

4. point out the type of error in the following program:

#include <iostream>

using namespace std;

int main()

{

      int h=10; w=12;

      cout << "Area of rectangle " << h+w;

}

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 9 : Introduction to C++ : Example Basic C++ Programs |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.