Professional Documents
Culture Documents
PF Quiz 2 Solution
PF Quiz 2 Solution
2. Size of _unsigned long___ data type is always at least 32 bits, and it can store only
non-negative integers. (1)
3. What will be displayed on console when following lines of code will be executed: (4)
cout << “\r\b Computers are \r designed to follow instructions \n\t A computer program is”;
cout << “\t\n a set of instructions that tells the computer \”\’how to solve a problem \” or”;
cout << “\b\b\b\b perform a task”;
4. What will be displayed on console when following lines of code will be executed:
(3+4+3)
int x; float y; char z;
cin >> x >> z >> y; // Assume user enters 22.65 A 9.1
cout << "x= "<< x;
cout << ", y= "<< y;
cout << ", z= " << z;
Output:
22.65 A 9.1
X= 22, y= 65, z= .
char ch1,ch2;
cin>> ch1; // Assume user enters touchpad
cin.ignore(3,'a');
cin.get(ch2);
cout << "you entered: " << ch1 << "," << ch2;
Output:
Touchpad
Output:
Hi ali
5. Draw cells and then write output according to exact format. (6)
#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
float num1=320, num2=10.1, num3=1.123456789;
cout << setprecision(3) << setw(5) << num1 << setw(5)<< num2 << setw(5) << num3 << endl;
cout << showpoint << setw(5) << num1 << setw(5)<< num2 << setw(5) << num3 << endl;
cout << fixed << setw(5) << num1 << setw(5)<< num2 << setw(5) << num3 << endl;
Output:
3 2 0 1 0 . 1 1 . 1 2
3 2 0 . 1 0 . 1 1 . 1 2
3 2 0 . 0 0 0 1 0 . 1 0 0 1 . 1 2 3