# CS201 Assignment 1 Solution 2021

**CS201 – Introduction to Programming**

**Assignment No. 1**

Semester: Spring 2021

#### #CS201 Assignment 1 Solution 2021

__Instructions__

__Instructions__

**Please read the following instructions carefully before submitting assignment:**

**It should be clear that your assignment will not get any credit if:**

**Assignment is submitted after due date.****Submitted assignment does not open or file is corrupt.****Assignment is copied (From internet/students).**

__Recommended tool to develop Assignment__

__Recommended tool to develop Assignment__

**Dev C++**

**Objectives:**

To enable students to understand and practice the concepts of:

- Data Types and Variables
- Arithmetic and Logical Operators
- Expression solving
- If-else statements
- repetition structure

__Assignment Submission Instructions__

__Assignment Submission Instructions__

You have to submit only**.cpp** file on the assignments interface of CS201 from your LMS account. *Assignment submitted in *__any other format__* will be scaled with *__zero mark__*. **So, check your solution file format before submission.*

For any query related to assignment, please contact cs201@vu.edu.pk.

** Lectures: 1 to 6**

### CS201 Assignment 1 Solution 2021

### Assignment Question

An expression is given here. You are required to write a C++ program that solves the given mathematical expression.

Z = x^{2} + 2xy – x/y

set the values of x = 2 and y = 1

Three main tasks are to be done by each student:-

- Expression solving
- Decisions making (if-else structure)
- Repetition structure (while loop).

After evaluation of above expression, you should add the value of **z** to last digit of your vu id. As a result,

- If you get an odd number, then you should print your VU id using while loop. This while loop should run as many times as odd number you got from (z+ last digit of your vu id).

For example, suppose the value of z is 2 and the student’s id is BC123456781. Then by adding last digit of vu id 1 to value of z, result will be 3 which is an odd number. In this case, program should print your VU ID for 3 times using while loop.

Sample screen shot::

- If you get an even number, then you should print your Name using while loop. This while loop should run as many times as even number you got from (z+ last digit of your vu id).

For example, suppose the value of z is 2 and the student’s id is BC123456782. Then by adding last digit of vu id 2 to the value of z, result will be 4 which is an even number. In this case, program should print your Name for 4 times using while loop.

Sample screen shot::

If you face an error while doing this assignment Here is a YouTube video for this assignment.

```
#include <iostream>
using namespace std;
main()
{
int x,y,z, vid=6,i=1;
x=2; y=1;
z= x*X + 2*x*y-x/y;
cout<<"After evalution of expression z values is :" << z<<end1;
cout<<"Last digit of my vu id is :" <<vid<<end1;
vid= vid +z;
if(vid%2==1)
{
cout<< "i got an odd number "<<vid<<end1;
while(i<=vid)
{
cout<< "iteration :"<<i<<end1;
cout<<"my vu is id BC200202206"<<end1;
i++;
}
}
else
{
cout<< "i got an even number "<<vid<<end1;
while(i<=vid)
{
cout<<" iteration :"<<i<<end1;
cout<<"my name is Fatima "<<end1;
i++;
}
}
}
```