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

Name: Talha Bin Tauseef Enrollment no: 01-133202-129

Programming Fundamentals Lab CSL-112


Instructor: Engr. Qasim Hussain

Midterm Exam
Implementation section:
Note:
You are supposed to implement the following scenario into code by your own. Prepare a
document containing the question, Flow chart/Algorithm, solution, and console result
screenshots. You must upload the document on LMS today 20-Apr-2021.
To avoid any issue at very last moment, try doing this thing before last time and submit well
before ending time.
Please make sure to produce your own solutions, as copying from internet/ any other source
including your class fellows can cause serious penalties for you.

Question:
a) Write a C++ program to calculate the sum of all the numbers whose digit at all places
are same from a given range of numbers. User will input starting and ending number.
Program will calculate the sum.

For example: starting value : 5 ; ending value : 100 ;

Same digit number in range are: 11,22,33,44,55,66,77,88,99

starting value : 5 ; ending value : 1000 ;

Same digit number in range are:


11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999

Program will find these numbers from range and add them to find result.

Code :
#include<iostream>
using namespace std;
int main()
{
int x, y, sum = 0, temp = 1;
cout << "Starting Value: "; cin >> x;
cout << "Ending Value: "; cin >> y;
for (int k = 0; k <= 4; ++k)
{
temp = temp * 10 + 1;

4/18/2021
for (int i= 1; i<= 9; ++i)
{
if (x <= (temp * i) && (temp * i) <= y)
{
if (temp * i > 10)
sum = sum + (temp * i);
cout << temp * i << ",";
}
}
}
cout << "Sum of All is: " << sum;
return 0;
}

Algorithm:

Variable Declaration: x, y, sum=0, temp=1;

Input: x, y.

For loop: (int k = 0; k <= 4; ++k), temp = temp * 10 + 1; (int i= 1; i<= 9; +


+i).

If statement: (int i= 1; i<= 9; ++i), (temp * i > 10).

Output: Displayed as sum of all:

Output:

4/18/2021
Mid term PF Sec B

* Required

Maximum value that we can store in an integer type variable


is? * (1 Point)

(2^8)-1 ; where ^ denotes power

(2^32)-1 ; where ^ denotes

power (2^ 16)-1 ; where ^

denotes power Needs more

information

A= 1010001 1
4/18/2021
B= 01001100
result of A||B will be? *
(1 Point)

11111111

11101111

Needs more information

00000000

4/18/2021
3

Suppose, you want to record the mid term marks of every student in your
section B for programming fundamentals Lab. What is suitable option to write
code for this task.
You can you multiple options if you feel them
correct. * (1 Point)

decision structures

for loop

nested for loop

while or do while loop

Suppose, we are creating an application where user have to input passcode for
access. Passcode needs to be 4 digits long and odd number. What are the
possible operators/operations that we need to use to accomplish this task.
You can choose more than one option, if you feel them as
correct. * (1 Point)

relational operators

decision structures

mod operators

logical operators
5

Following flow chart is representing which C+ + structure? *


(1 Point)

8oolean Expression
alse True

A statement or block of statements 2 A stotement or block of statements 1

needs more information

Repitition structures

Decision structure

6 code will not execute as it

has errors 4 5 6 7 8 9

A=26;
B=A< < 3;
what will be the value of B. *
(1 Point)

208

what is the output of the following


code? * (1 Point) needs more information

no visible output on console

needs more information


int main() for ( j 4; j » 10 ; j t )

int j;
ret urn 0;
8

what are the possible values returning from a relational


expression? * (1 Point)

can be infinite man

needs more information to determine

depends upon operating system

9
int main()
Identify the errors in this code.
You can choose more than one bool i;
option. * (1 Point)
do

awhile(i 20)

ret urn 0;

a part among four loop parts we studied is

missing do while loop syntax issue

data type issue

parts among four loop parts we studied are


missing
10

what will be the output of the


following code? * (1 Point)
int main()
48
i nt i ;
i can not determine the output

2 4 6 8 10 for(i 1; i 10; i+ )
.r
code has errors so will not execute
if(i 4 0)
.f

This content is neither created nor endorsed by Microsoft. The data you submit will be sent to the form owner.

@ Microsoft Forms

You might also like