Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Programming Fundamentals

Quiz 2 Total Marks: 22

Student Roll No.______________________ Total Duration: 20 minutes

1. The expression !4 < 5 will evaluate to ___True OR 1______________ (1)

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

you entered: t,h


char name[10];
cout << "Enter your name: ";
cin >> setw(8);
cin.getline(name,5); // Assume user enters ali ahmed
cout << "Hi " << name << endl;
cout << "Program ended.";

Output:

Enter your name: ali ahmed

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

You might also like