0% found this document useful (0 votes)
279 views

CS201 Assignment 1 Solution

This C++ program is the solution to CS201 Assignment 1 for Spring 2021 provided by VU Daily. It contains the code to: 1) Define variables and perform math operations to calculate the value of Z 2) Get the last digit of a sample student ID number 3) Use an if/else statement to output different messages based on if the last digit is even or odd

Uploaded by

Muhammad Zeeshan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
279 views

CS201 Assignment 1 Solution

This C++ program is the solution to CS201 Assignment 1 for Spring 2021 provided by VU Daily. It contains the code to: 1) Define variables and perform math operations to calculate the value of Z 2) Get the last digit of a sample student ID number 3) Use an if/else statement to output different messages based on if the last digit is even or odd

Uploaded by

Muhammad Zeeshan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS201 ASSIGNMENT 1 SOLUTION

SPRING 2021
SOLUTION
#include <iostream>

using namespace std;

int main()
{
cout<<" ---CS201 ASSIGNMENT 1 SOLUTION 1 SPRING
2021----"<<endl;
cout<<" ---Program by VU Daily----"<<endl;
cout<<" "<<endl;

int x,y,Z;
x=2;
y=1;

Z = (x*x)+(2*y*x)-(x/y);
cout<<"After evaluation of given expression the value of z =
"<<Z<<endl;

string ID = "BC";
int id2 = 200205672; // remove and enter any student id here
(not real)
string name = "CH RAHMAN"; // enter your name into my name
int lastdigit;
int Gotnumber;

lastdigit = id2 % 10;


cout<<"--Last digit of VU ID is "<<lastdigit<<endl;
Gotnumber = Z + lastdigit;

// using if else condition


string test;
int n = 1;
if ((lastdigit % 2) == 0)
{
test = "even";
cout<<"I got an "<<test<<" number "<<Gotnumber<<endl;
while (n <= Gotnumber)
{
cout<<"Iteration: "<<n<<endl;
cout<<"My name is "<<name<<endl;
n++;
}
}
else
{
test = " odd";
cout<<"I got an "<<test<<" number "<<Gotnumber<<endl;
while(n <= Gotnumber)
{
cout<<"Iteration: "<<n<<endl;
cout<<"My VU ID is "<<id2<<endl;
n++;
}
}

return 0;
}

You might also like