Home | | Computer Science 11th std | Basic C++ Programs in Data Types, Variables and Expressions

# Basic C++ Programs in Data Types, Variables and Expressions

Basic C++ Programs in Data Types, Variables and Expressions

## setprecision ( )

### Example:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

float hra = 1200.123;

cout << setprecision (5) << hra;

}

### Example:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

cout.setf(ios::fixed);

cout << setprecision(2)<<0.1;

}

## (1) Implicit type conversion:

### For example:

#include <iostream>

using namespace std;

int main()

{

int a=6;

float b=3.14;

cout << a+b;

}

## (2) Explicit type conversion

### Example:

#include <iostream>

using namespace std;

int main( )

{

float varf=78.685;

cout << (int) varf;

}

### Example:

#include <iostream>

using namespace std;

int main()

{

double varf=178.25255685;

cout << (float) varf << endl;

cout << (int) varf << endl;

}

178.253

178

## 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()

{

float area;

cout << "\n Enter 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++ : Basic C++ Programs in Data Types, Variables and Expressions |