CS201 MID TERM SOLVED MCQs || PAST PAPERS || GROUP-1 || INTRODUCTION TO PROGRAMMING || VuTech Visit Website For More Solutions www.vutechofficial.blogspot.com …
CS201P ASSIGNMENT NO. 1 FALL 2022 || 100% RIGHT SOLUTION || INTRODUCTION TO PROGRAMMING (PRACTICAL) || BY VuTech
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
Assignment Submission Instructions
You are required to submit only .cppfile on the assignments interface of CS201P at VU-LMS. Assignment submitted in any other format (like doc, docx, jpg, png, giff, etc) will not be accepted and will be graded zero marks. So, check your solution file format before submission.
For any query related to assignment, please contact cs201p@vu.edu.pk
Problem Statement:
Sometimes in programming, there may be a need to run a block of code repeatedly. In general, the programmingstatements are executed in order. Different control structures offered by programming languages allow for more complex execution paths. A loop statement allows us to execute a statement or collection of statements multiple times. Conditional branching statement (if-else), on the other hand, controls the flow of execution of statements based on some condition. If the given condition is true, the code inside IF block is executed, otherwise Else block code is executed.
Now keeping in mind, the above discussed concepts,write a C++ program using FOR loop and If-Else statement that performs the following tasks:
1Print your VU Id.
2Add first and last numeric digit of VU Id, and store the result in variable “sum”.
3Display the result of sum on screen.
4If sum is greater than 7 then print the “Welcome to VU”. Number of iterations of FOR loop should be equal to the sum.
.If sum is less than 7 then print the “Welcome to CS201P”. Number of iterations of FOR loop should be equal to the sum.
For example, suppose the student id is BC123456781. Then by adding first and last numeric digit of VU Id, we get the value of 2. In this case, program should print “Welcome to CS201P” for 2 times using FOR loop and vice versa.
Sample Screenshots: For the given supposed VU Id (BC123456781), following will be the output of the program.
NOTE:Student’s id is a supposed value (not real) in above example. You will print your own VU Id otherwise you will get zero marks.
Wish you Good Luck!
KINDLY, DON’T COPY PASTE
SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
SOLUTION
#include <iostream>
using namespace std;
int main()
{
char *vu_id;
int first_digit, last_digit, sum;
vu_id = "BC20001005";
First_Digit = 2;
Last_Digit = 5;
Sum = First_Digit + Last_Digit;
cout<<"My VU ID is:\t"<<vu_id<<endl;
cout<<"The sum of first and last digit of VU ID is:\t"<<Sum<<endl;
if (Sum>7) // sum > 7
{
for (int i = 0; i<Sum; i++)
{
cout<<"Iteration "<<i+1<<": Welcome to VU"<<endl;
}
}
else if (Sum<7) // sum < 7
{
for (int i = 0; i<Sum; i++)
{
cout<<"Iteration "<<i+1<<": Welcome to CS201P"<<endl;
}
}
else// sum = 7
{
cout<<"The Sum is Equal to 7";
}
return 0;
}
KINDLY, DON’T COPY PASTE
SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES
We provide Virtual University of Pakistan Study Materials such as Solution of Assignments, GDBs, Mid Term Solved Papers, Final Term Solved Papers, Mid Term Solved MCQs, and Final Term Solved MCQs. We also provide regular Semester Quizzes, Updated Handouts, and Short Questions and Answers. We help you with your research and many other educational-related topics, as far as we know. Furthermore, Share your problem with us and Please feel free to ask any related questions.