Professional Documents
Culture Documents
Programming Fundamentals Lab CSL-112: Instructor: Engr. Qasim Hussain Midterm Exam
Programming Fundamentals Lab CSL-112: Instructor: Engr. Qasim Hussain Midterm Exam
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.
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:
Input: x, y.
Output:
4/18/2021
Mid term PF Sec B
* Required
information
A= 1010001 1
4/18/2021
B= 01001100
result of A||B will be? *
(1 Point)
11111111
11101111
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
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
8oolean Expression
alse True
Repitition structures
Decision structure
has errors 4 5 6 7 8 9
A=26;
B=A< < 3;
what will be the value of B. *
(1 Point)
208
int j;
ret urn 0;
8
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;
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