Escolar Documentos
Profissional Documentos
Cultura Documentos
LAB
SP19-MCS-033
Sir.Shafiq Ahmed
22-Sep-2019
1. If you want the user to input an integer value into your program for
a variable named number what are two lines of code you could write
to ask the user to do it and to input the value into your program?
Ans:
#include<iostream>
main()
int number;
cin>>number;
return 0;
}
Output
Ans:
The \n stands for New Line. It is use for move cursor from above to new line.
Ans:
#include<iostream>
using namespace std;
main()
cout<<"Hello, "<<"first_name!\n";
return 0;
Output
4. What is a literal?
Ans:
A literal is refers to a fixed values in programming that cannot be alter in any
program.
5. What kinds of literals are there?
Ans:
There are five types of literals that are following:
1. Integer literals
2. Boolean literals
3. Character literals
4. String literals
5. Floating Point Literals
6 .What effect do tabs, spaces, and new lines have on the program?
Ans:
Tabs and spaces create spaces between words and new line move cursor from
above line to next line.
Ans:
Data types Sizes
Char 1 byte
Int 4 bytes
Double 8 bytes
Ans:
In programing every literals has its own size whether it will be int, char, double or
float. The size define the amount of space require by the literal to store it in a memory.
A byte is used to measure the size of small entities. One byte is equivalent to the 8 bits.
9. What is the difference between = and ==?
Ans:
= is the assignment operator. b = 1 will set the variable b equal to the value 1.
== is the equality operator. It returns true if the left side is equal to the right side, and
returns false if they are not equal.
Ans:
Initialization is giving a variable its initial value. It differs from assignment, because
assignment is giving a variable a new value. You can assign an initial value to something
else, but you can't initialize something that's been assigned.
Ans:
If we use illegal names for different variables it gives us error.
For example:
#include<iostream>
main()
int double=0;
float class;
char name='A';
cout<<"Mariam Fazal Abbasi\n"<<"SP19-MCS-033\n"<<"MCS";
return 0;
If we use legal names for variable than it doesn’t show any output for these variables.
For example:
#include<iostream>
main()
int a=0;
float b;
char name='A';
Output
Ans:
#include<iostream>
cin>>miles;
kilometers = miles/1.609;
cout<<"Kilometers :"<<kilometers<<endl;
return 0;
Output
13. Write a program that prompts the user to enter two integer
values. Store these values in int variables named val1 and val2. Write
your program to determine the smallest, largest, sum, difference,
product, and ratio of these values and report them to the user.
Ans:
#include<iostream>
main()
int val1,val2;
cin>>val1>>val2;
if (val1>val2)
if (val1<val2)
return 0;
Output
14. Modify the program above (Q13) to ask the user to enter floating-
point values and store them in double variables. Compare the outputs
of the two programs for some inputs of your choice. Are the results
the same? Should they be? What's the difference?
Ans:
#include<iostream>
main()
float val1,val2;
cin>>val1>>val2;
if (val1>val2)
if (val1<val2)
return 0;
}
Output
The value of both programs are different with changing the data types.
Ans:
#include<iostream>
main()
int num;
cout<<"Enter a number\n";
cin>>num;
if(num%2==0)
else
return 0;
}
Output
10
20
19
Ans:
#include<iostream>
using namespace std;
main()
int a =10;
cout<<a<<endl;
int b=a+10;
cout<<b<<endl;
int c=--b;
cout<<c<<endl;
return 0;
}
Output
Year Result
-----------------
1990 135
1991 7290
1992 11300
1993 16200
Use a single cout statement for all output .Also, revise the program to
show the same table by using cin object .Which takes all the values
from user and draw the same table.
Ans:
#include<iostream>
main()
cout<<"Years\tResult\n";
cout<<"-------------\n";
return 0;
}
Output