You are on page 1of 5

Setw manipulator The setw stands for set width.

. This manipulator is used to set width of the output on the out put device. For example Setw (m) Where m specifies the width of the out put field. It is an integer value If we want to print the Geological in first 10 columns and engineering in next 15 columns , so the out put statement is written as Cout<< setw(10)<<Geological<< setw (15)<< engineering

Programs # include<iostream.h> # include <iomanip.h> # include <conio.h> Main() { Clrscr(); Cout<< setw(5)<<62<<setw(5)<<8<<endl; Cout<<setw(5)<<100<<setw(5)<<77<<endl; Cout << setw(5)<<5<<setw(5)<<162<<endl; }

Write a program to assign two variables by assignment statement .interchange the values and print the result on the screen #include <iostream.h> Main () { Int a , b , c; a= 200; b = 100; c= a; a= b; b= c; Cout<< value of a = << a<< endl; Cout << value of b = <<b<<endl; } Write a program in C++ to get two numbers from keyboard during program execution . Calculate the sum and product of the numbers and then print the result on computer screen #include <iostream.h> # include <conio.h>

Main() { Int n1 ,n2 ,s,p; Clrscr(); Cout << enter first number ? ; Cin >> n1; Cout << enter second number ? ; Cin>> n2; s=n1+n2; p = n1*n2; Cout << sum of numbers = <<s<<endl; Cout<< product of numbers = << p<<endl;

Write a program to get name and age (in years) of a person calculate the age in months and print the name of the person and its age in months # include <iostream.h> # include <conio.h> Main () { int age ; Long int age_mon; Char name [50]; Clrscr(); Cout << enter the name of the person ; Cin >> name ; Cout << enter age of the person in years; Cin>> age; Age_mon = age*12;

Cout << name of the person = name << endl; Cout << age in months = << age_mon<<endl; } Write a program in C++ to read the name of the student and marks obtained in three subjects C++ , mineralogy , Applied geology . Calculate total and average . Input the data using cin object . Each subject has a maximum of 100 marks. #include <iostream.h> # include <conio.h> Main() { Float avg ; Char name [20]; Int total , cpp , min , geo; Clrscr(); Cout<< Enter the name of student; Cin >> name; cout << enter marks obtained in C++; Cin>>cpp; Cout<< enter marks obtained in mineralogy; Cin>> min; Cout<< enter marks obtained in applied geology; Cin>> geo; Total = cpp+min+geo; Avg=total/3.0; Cout<< name of the student = <<name << endl; Cout<< Total marks = <<total <<endl; Cout << Average marks = << avg<<endl;}

Wirt a program in C++ to read temperature in Fahrenheit . Convert the temperature to Celsius degrees by using the formula C=5/9(f-32)

You might also like