Assign 1
Assign 1
MGR
break;
case 2:
cout<<”\n”<<”Friction is drag”;
break;
case 3:
cout<<’\n’<<”Practice makes perfect, then nobody is perfect”;
}
}
14) What is the output of the following program?
# include<iostream.h>
void main()
{
int i=4;
for(;;)
{
cout<<i++<<”\t”;
if(i>10)
break;
}
}
15) What is the output of the following program?
# include<iostream.h>
void main()
{
int i=4;
while( )
{
cout<<i++<<”\t”;
if(i>10)
break;
}
}
16) Assuming there are 7.481 gallons in a cubic foot. Write a program that asks the user to enter a number
of gallons and then displays the equivalent in cubic feet.
17)Write a program that generates the following output?
1990 135
1991 7290
1992 11300
1993 16200. Use a single cout statement for all output.
18) Write a program that generates the following output.
10
20
18
Use an integer constant for 10, an arithmetic assignment operator to generate the 20, and a decrement
operator to generate the 18.
19)What are the differences between run time and linker errors?
20)Trace the following code fragment, showing the value of each variable each time it changes;
int x,y,z;
x=y=z=6;
x*=y+=z-=4;
MGR
21) What is the difference between reserved word and an identifier?
22) How the following expression is evaluated?
(x <y?-1: (x == y? 0:1) ) ;
23) Write a program that reads user’s age and then prints “you are child” if the age<18, “you are adult” if
age is between 18 and 65, and “senior citizen” if age>=65.
24) Write and run a program that reads two integers and then uses the conditional expression operator to
print “multiple” or “not” according to whether one of the integers is multiple of the other.
25) Write a program that simulates a simple calculator. It reads two integers and acharceter. The character
is operand. Simulate all arithmetic operations.
26) Write a program that reads four integers and prints the minimum and maximum. Use conditional
operators.
27) write a program that reads a grade A,B,C,D or F and then prints “Excellent” ,”Good”, “Fair”, ”Poor”
or “Failure”. Use case statement.
28) Write a program that reads a character and then prints “It is vowel” if it is vowel, “It is an operator” if
it is one of five arithmetic operators and “It is something else” if its anything else. Use case statement.
29) Write a program that reads two characters and two integers. If the first character and the two
characters together form one of six relational operators, then the two integers are compared using that
operator and a message describing the result is printed.
For example run could look like this,
!= 33 77
33 is not equal to 77
30) What is the output of the followi
ng program?
#include<iostream.h>
void main()
{
const double pi;
int i;
pi=3.14566;
i=9;
cout<<pi<<”\t”<<n;
}
31) What is difference between do-while and while loops?
32) What are the advantages of giving different names to data types using typedef keyword?
33) Write a program to find the integer square root of a given number. That is the largest integer whose
square is less than or equal to the given number.(don’t use inbuilt function).
34) write a program that reverses the digits of given number. Take care to handle negative numbers.
35) Describe the output of the following fragment.
int i=0;
while(i<5){
if(i<2){
i+=2;
continue;}
else
cout<<++i<<endl;
cout<<”Bottom of the loop\n”;
}
36)Write a program that inputs 4 positive integers day, month, year and days and then prints two dates
that they represented by the given day, month and year, and the date that occurs days later. For
example, if the 4 inputs are 6, 4, and 1997and 100, then two dates printed would be April 6,1997 and
July15,1997(for 6/4/97+100 days).
MGR
37) Write a temperature conversion program that gives the user the option of converting Fahrenheit to
Celsius to Celsius to Farenheit. Then carry out the conversion. Use floating point numbers. When it
finishes the conversion, the program should ask if the user wants to another conversion. The response
can be ‘y’ or ‘n’. Some sample interaction with program might look like this.
Type 1 to convert Fahrenheit to Celsius,
2 to convert Celsius to Fahrenheit: 1
Enter temperature in Fahrenheit: 70
In Celsius that’s 21.1111
Do you want another conversion (y/n)?:n
38) Operators such as >> which read input from the keyboard, must be able to convert a series of digits
into number. Write a program that does the same thing. It should allow the user to type up to six digits
and then display the resulting number as type long integer. The should be read individually as
characters.( hint: subtract 48 or ‘0’ to go from ASCII to a numerical digit).
39) What is the output of following program?
# include<iostream.h>
void main()
{
int i=2;
switch(i)
{
cout<<”hello”;
case 1:
cout<<endl<<”\nhi”;
break;
case 2:
cout<<”\nbye”;
break;
default:
cout<<”\ngood morning”;
}
}
40) What is the output of the following code?
#include<iostream.h>
void main()
{
int x=10,y=100%10;
for(i=1;i<=10;i++);
if(x!=y);
cout<<x<<”\t”<<y;
}
41) Point out the error if any in the following code.
#include<iostream.h>
void main()
{
int x=1;
switch(i)
{
case 1:
cout<<”Radoactive cats have 18 half-lives”;
break;
case 1*2+4:
MGR
cout<<”\nBottle for rent-inquire with in”;
break;
case i:
cout<<”Life is rocking\n”;
break;
defult:
cout<<”\nif you have nothing to do don’t do it here”;
}
}
42) What is the output of the following code?
#include<iostream.h>
void main()
{
int x=5;
while(x-- >= 0) cout<<x;
cout<<endl;
x=5;
while(x-- >= 0) cout<<x;
}
43) What is the output of the following code?
#include<iostream.h>
void main()
{
float a=0.7;
if(0.7>a)
cout<<”hi\n”;
else
cout<<”hello”;
}
44) What is the output of the following code?
#include<iostream.h>
void main()
{
int x,y,z;
x=y=z=1;
z=++x || ++y && ++z;
cout<<x<<y<<z;
}
45) What is the output of the following code?
#include<iostream.h>
void main()
{
int k,num=30;
k=(num > 5 ? (num <= 10 ?100:200):500);
cout<<num;
}
46) What is the output of the following code?
#include<iostream.h>
void main()
{
char j=1;
MGR
while(j <= 255)
{
cout<<x;
j++;
}
}
47) On executing the following code how many times would the message “keep it up” would be
generated?
#include<iostream.h>
void main()
{
int x;
for(x=-1;x<=10;x++)
{
if( x<5)
continue;
else
break;
cout<<”Keep it up\n”;
}
}
48) What is the output of the following code?
#include<iostream.h>
void main()
{
char ch=’A’;
cout<<”The letter is\n”;
cout<<(ch >= ‘A’ && ch<=’Z’? ch + ‘a’ – ‘A’ : ch);
cout<<endl;
cout<<(ch >= ‘A’ && ch<=’Z’? ch : ch + ‘a’ – ‘A’);
}
49) Write a program to find factorial of a given number? Be prepared to handle zero and negative number
also.
50) Write a program to read a character (ch) and integer number (n) to print characters in the shape of
parallelogram with 2n rows.
51) Write a pgm to find whether a year is leap year or not?
52) Write a program to find maximum number of days in a month?
53) Write a program to find whether entered date is earlier than the other or not?
54) The following color code is assigned to different colors. Write a program to accept the color code and
display the appropriate color code. Use enum.
Color code color
1 Red
2 Blue
3 Green
4 Yellow
5 Purple
55) Write a program to accept three sides of a triangle and display the type of the triangle.
56) Define a macro SWAP(a,b) that performs swapping of two floats.
57) What are the differences between macro and function?
MGR
58) What is the output of the following program?
#include<iostream.h>
#define SQR(x) (x*x)
void main()
{
int a, b=2;
a=SQR(b+2);
cout<<a;
}
59) What is the output of the following program?
#include<iostream.h>
#define CUBE(x) (x*x*x)
void main()
{
int a, b=2;
a=CUBE(b++);
cout<<a;
}
60) What is the output of the following program?
#include<iostream.h>
#define FUN(arg) do{\
if(arg)\
cout<<”Have fun\n”;\
}while(arg--);
void main()
{
int b=2;
FUN(b);
}
61) What is the output of the following program?
#include<iostream.h>
#define X (4+Y)
#define Y(X+3)
void main()
{
cout<<(4*X+2);
}
62) What is the output of the following program?
#include<iostream.h>
#define MAX(a,b) (a>b?a:b)
void main()
{
float x;
x=MAX(3+2,7+2);
cout<<x;
}
63) What is the output of the following program?
#include<iostream.h>
#define MAX(a,b,c) (a>b?a>c?a:c:b>c?b:c)
void main()
MGR
{
float x;
x=MAX(3+2,7+2,3+7);
cout<<x;
}
64) What will be the output of t he following program?
#include<iostream.h>
void main()
{
enum value{val1=0,val2,val3,val4,val5}var;
cout<<sizeof(var);
}
65) What will be the output of t he following program?
#include<iostream.h>
#define TAB ‘\t’
void main()
{
enum days{MON=-1,TUE,WED=6,THU,FRI,SAT};
cout<<MON<<TAB<<TUE<<TAB<<WED<<TAB<<SAT;
}
66) What will be the output of t he following program?
#include<iostream.h>
void main()
{
enum status{pass,fail,atkt};
status stud1,stud2,stud3;
stud1=pass;
stud2=atkt;
stud3=atkt;
cout<<stud1<<” “<<stud2<<” “<<stud3;
}
67) Write a program that counts number of 1-bits in integer input.
68) Write a program that converts upper case letters to lower case and vice versa.
69) Write a program to count number white spaces, digits, alphabets in the entered text.
70) Write a program that counts both lower case and uppercase vowels, that is your program should count
both ‘a’ and ‘A’ and so forth. Count number of occurrences of each character.
71) Given two vectors of ints, write a program to determine whether one vector is prefix of the other. For
vectors of unequal length, compare the number of elements of the smaller vector. For example
vectors(0,1,1,2) and (0,1,1,2,3,5,8), your program should return true.
72) An electricity board charges the following rates to domestic users to discourage large consumption of
energy.
For the first 100 units - 60P per unit
For next 200 units - 80P per unit
Beyond 300 units - 90P per unit
All users are charged a minimum of Rs. 50.00. If the total amount is more than Rs. 300.00 then an
additional surcharge of 15% is added.
Write a program to read the names of users and number of units consumed and print out the charges
with names.
73) Write a program to count blanks, tabs and newlines.
74) Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and
each back slash by \\. This makes tabs and backspaces visible in an unambiguous way.
MGR