Semester: Fall 2019

CS201 – Introduction to Programming Total Marks: 20

Due Date: November 14, 2019

Instructions

Please read the following instructions carefully before submitting assignment:

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

o Assignment is submitted after due date.

o Submitted assignment does not open or file is corrupt.

o Assignment is copied (From internet/students).

Software allowed to develop Assignment

- Dev C++

Objectives:

To enable students to understand and practice the concepts of:

• Variables and operators

• Loops or repetition structures

• If-else statements

• Functions

• Random number generation

• Control random number in specific range

Assignment Submission Instructions

You have to submit only.cpp file on the assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.

Please note again, assignment submitted other than .cpp format will get zero marks.

Assignment

Programming is a nice tool which can be used to make our life easier. With the help of programming we can do many things auto generated and efficiency. As a programmer first task of this semester is given to you is develop a console-based application for school teachers. This application will auto generate questions for Grades 1, 2, 3, 4 and 5. Using this application teacher will be able to give different paper to each student.

Assignment Statement:

Write a menu-based program in C++ that will take input from user(teacher) and fulfill following requirements.

• There should be a menu that allow to select grade of class.

• Created questions should be mixed type (addition and subtraction).

• User will give number of questions that will be generated for a paper.

• Ratio of addition and subtraction questions is not fixed. It will random, a paper can have more questions of one type than other. See sample output screenshot.

• Number of minimum and maximum digits in paper of grade 1 will be two.

• Number of minimum and maximum digits in paper of grade 2 will be three.

• Number of minimum and maximum digits in paper of grade 3 will be four.

• Number of minimum and maximum digits in paper of grade 4 will be five.

• Number of minimum and maximum digits in paper of grade 5 will be six.

• Screen shot of required application is given below as simple output.

• Most critical requirement is, the operand (number) on left side of subtraction sign must be larger than the number on right side of sign (operator). This requirement is highlighted in sample screenshot too.

• In case of addition operation, the operand (number) on left side of addition sign can be larger or smaller from the number on right side of sign (operator).

Solution instructions:

• Variables, loops, if-else, rand() function with % operator, functions (one which return a value and one which do not return a value) will help you to solve the problem.

• Use rand() function to generate a random number. You can control the range of number with the help of modulus (%) operator.

• To use rand() function you must include “stdlib.h” header file.

• To control the range of random number rand() % N can help, if value of N will be 100 then range of randomly generated number will be 0 to 99.

• If you want to control the range of random number between 10 to 19 then following formula will help.

o [10 + rand() % (19 – 10 + 1)]

Sample output:

Lectures Covered: (Lecture # 1- 10) and Solution Deadline: (November 14, 2019).

]]>Write a C++ program that performs the following tasks:

1-Print your name and VU id.

2-Add last 3 digit of your VU id.

3-Display the result of sum on screen.

4-Use if-else statement ::

a) If sum is odd then print your name using while loop. Number of iterations of while loop should be equal to the sum.

b) If sum is even then print your VU id using while loop. Number of iterations of while loop should be equal to the sum.

[use remainder operator on sum value to determine the odd and even value for if condition]

For example, suppose the student id is BC123456781. Then by adding last 3 digits of vu id, we get 16 which is an even number. In this case, program should print your VU ID for 16 times using while loop.

```
// C201 Assignment No: 1 Fall2021
#include <iostream>
#include <string>
using namespace std;
void printnameid(string studentid, string studentname);
int calculatelastthreedigits(string studentid);
int main()
{
string studentid="bc123456789";
string studentname="ZAHID";
printnameid(studentid,studentname);
int TotalLastThreeDigits=calculatelastthreedigits(studentid);
int counter=1;
int a,b,c;
a=6;
b=4;
c=0;
cout<<"Sum of Last Three Numbers ="<<a+b+c;
cout<<"\n\n";
if ( TotalLastThreeDigits % 2 == 0) // Divide by 2 and see if the reminder is zero? then it is even otherwise it is odd number
{
cout << "the sum is an even value: \n\n"; cout<<"++++++++++++++++++++++++++++++++++++++++++++ \n\n"; while(counter <= TotalLastThreeDigits)
{
cout << " Iteration: " << counter << "\n";
cout << "My student id is:" << studentid << "\n";
counter++;
}
}
else
{
cout << "the sum is an odd value: \n\n";
while(counter <= TotalLastThreeDigits)
{
cout << " Iteration: " << counter << "\n";
cout << "My name is " << studentname << "\n";
counter++;
}
}
return 0;
}
void printnameid(string studentid, string studentname){
cout<<"My name is " << studentname << "\n\n\n";
cout<<"My student id is:" << studentid << "\n\n\n";
}
int calculatelastthreedigits(string studentid) {
int end=studentid.length(); // Ending point that is total length of string
int start=end-3; // Starting point
string lastthreedigits=studentid.substr(start,end); // Trim the last three digits;
int total=0;
//Calculate the sum of last three digits
for ( int index=0; index < lastthreedigits.length(); index++) {
total += lastthreedigits[index] - '0';
}
return total; // return the total to calling statement.
}
```

]]>```
Assignment No. 1
```

Semester: Fall 2021

CS201 – Introduction to Programming Total Marks: 20

Due Date: 9-12-2021

Instructions

Please read the following instructions carefully before submitting assignment:

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

o Assignment is submitted after due date.

o Submitted assignment does not open or file is corrupt.

o Assignment is copied (From internet/students).

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

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
```

Assignment

Write a C++ program that performs the following tasks:

1-Print your name and VU id.

2-Add last 3 digit of your VU id.

3-Display the result of sum on screen.

4-Use if-else statement ::

a) If sum is odd then print your name using while loop. Number of iterations of while loop should be equal to the sum.

b) If sum is even then print your VU id using while loop. Number of iterations of while loop should be equal to the sum.

[use remainder operator on sum value to determine the odd and even value for if condition]

For example, suppose the student id is BC123456781. Then by adding last 3 digits of vu id, we get 16 which is an even number. In this case, program should print your VU ID for 16 times using while loop.

Sample screen shot::

Sample screen shot::

NOTE: Student’s name and id are supposed values (not real) in above example. You will print your own VU Id and Name otherwise you will get zero marks.

]]>```
Assignment No. 1
```

Semester: Spring 2021

CS201 – Introduction to Programming Total Marks: 20

Due Date:20th May 2021

Instructions

Please read the following instructions carefully before submitting assignment:

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

o Assignment is submitted after due date.

o Submitted assignment does not open or file is corrupt.

o Assignment is copied (From internet/students).

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

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
```

Assignment

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

Z = x2 + 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::

NOTE: Values of “z” and “student’s id” are arbitrary (not real).

]]>Assignment No. 1

Semester: Fall 2020

CS201 – Introduction to Programming Total Marks: 20Due Date: 26-November-2020

Instructions

Please read the following instructions carefully before submitting assignment:

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

o Submitted assignment does not open or file is corrupt.

o Assignment is copied (From internet/students).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

• If-else statementsAssignment 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 not be accepted and will be scaled with zero marks.For any query related to assignment, please contact cs201@vu.edu.pk.

Assignment

Information about an ABC organization is given below.

- There are 10 employees in the organization.
- There are 2 employees of level-A, 3 employees of level-B, 5 employees of level-C.
- The information about their salaries is given below.

a) The salary of level-A employee is Rs.1, 25,000.

b) The salary of level-B employee is Rs.80, 000.

c) The salary of level-C employee is Rs.45, 000.- Rs.600 is deducted from the salaries of all employees against staff welfare fund.
- If ANNUAL salary of an employee is more than Rs.600, 000, 1% tax is deducted from salary each month.

You are required to write a C++ program which finds

- Total monthly tax deduction for all employees.
- Total amount of welfare fund collected each month from all employees.
- Net monthly salary of an employee. (Level-A, level-B, level-C).

(Hint: Net_Monthly_Salary= Original_Salary- Monthly_Tax – Monthly_Welfare_Fund)- Total amount which organization pays to its employees each month.
- Also create a menu using (if-else) conditional statements, if a user wants to know about the separate tax collection of Level-A, Level-B, And Level-C employees.

If user enters 1, leve-A employee tax will be shown.

If user enters 2, leve-B employee tax will be shown.

If user enters 1, leve-C employee tax will be shown.

If user inputs wrong number then a message will be shown: “incorrect input”.Sample Screenshot of Output:

**Solution**

```
#include<iostream>
//#include<conio.h>
using namespace std;
int main()
{
float totaltax = 0, totalfund = 0, fund = 600, salaryA = 125000, salaryB = 80000, salaryC = 45000, Annaul_SalaryA=0,
Annaul_SalaryB=0, Annaul_SalaryC=0,salaryofall = 0, taxA = 0, taxB = 0, taxC = 0, netsalaryA = 0, netsalaryB = 0, netsalaryC = 0;
int num=0;
//Monthly welfare fund
totalfund = 10*fund;
//Annual salaries
Annaul_SalaryA = salaryA*12;
Annaul_SalaryB = salaryB*12;
Annaul_SalaryC = salaryC*12;
// Checking tax eligibility and Monthly Tax Calculation
if(Annaul_SalaryA > 600000)
{
taxA = salaryA*.01;
}
if(Annaul_SalaryB > 600000)
{
taxB = salaryB * .01;
}
if(Annaul_SalaryC > 600000)
{
taxC = salaryC * .01;
}
else
{
taxC = 0;
}
totaltax = taxA*2 + taxB*3 + taxC*5;
//Net salaries after deduction
netsalaryA = salaryA - taxA - fund;
netsalaryB = salaryB - taxB - fund;
netsalaryC = salaryC - taxC - fund;
//Total amount paid by university
salaryofall = salaryA*2 + salaryB*3 + salaryC*5;
cout<<"Total Monthly Tax deduction of all employees :\t"<<totaltax<<endl;
cout<<" Total amount of Welfare Fund collected : \t"<<totalfund<<endl;
cout<<" Net monthly salary of A Level employee : \t"<<netsalaryA<<endl;
cout<<" Net monthly salary of B Level employee : \t"<<netsalaryB<<endl;
cout<<" Net monthly salary of C Level employee : \t"<<netsalaryC<<endl;
cout<<" Total amount paid by university after a month :\t"<<salaryofall<<endl;
cout<<endl;
//Separate details of tax collection
cout<<"Enter 1 to know the tax collection of Level A employees "<<endl;
cout<<"Enter 2 to know the tax collection of Level B employees "<<endl;
cout<<"Enter 3 to know the tax collection of Level C employees "<<endl;
cin>>num;
if(num==1)
{
cout<<"tax collection of Level A employees is Rs."<<taxA*2<<endl;
}
else if (num==2)
{
cout<<"tax collection of Level B employees is Rs."<<taxB*3<<endl;
}
else if (num==3)
{
cout<<"tax collection of Level C employees is Rs."<<taxC*5<<endl;
}
else
{
cout<<"Incorrect input";
}
}
```

]]>```
Assignment No. 1
```

Semester: Fall 2020

CS201 – Introduction to Programming Total Marks: 20

Due Date: 26-November-2020

Instructions

Please read the following instructions carefully before submitting assignment:

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

o Submitted assignment does not open or file is corrupt.

o Assignment is copied (From internet/students).

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

• If-else statements

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 not be accepted and will be scaled with zero marks.

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

Assignment

Information about an ABC organization is given below.

- There are 10 employees in the organization.
- There are 2 employees of level-A, 3 employees of level-B, 5 employees of level-C.
- The information about their salaries is given below.

a) The salary of level-A employee is Rs.1, 25,000.

b) The salary of level-B employee is Rs.80, 000.

c) The salary of level-C employee is Rs.45, 000. - Rs.600 is deducted from the salaries of all employees against staff welfare fund.
- If ANNUAL salary of an employee is more than Rs.600, 000, 1% tax is deducted from salary each month.

You are required to write a C++ program which finds

- Total monthly tax deduction for all employees.
- Total amount of welfare fund collected each month from all employees.
- Net monthly salary of an employee. (Level-A, level-B, level-C).

(Hint: Net_Monthly_Salary= Original_Salary- Monthly_Tax – Monthly_Welfare_Fund) - Total amount which organization pays to its employees each month.
- Also create a menu using (if-else) conditional statements, if a user wants to know about the separate tax collection of Level-A, Level-B, And Level-C employees.

If user enters 1, leve-A employee tax will be shown.

If user enters 2, leve-B employee tax will be shown.

If user enters 1, leve-C employee tax will be shown.

If user inputs wrong number then a message will be shown: “incorrect input”.

Sample Screenshot of Output:

]]>```
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int selectGrade(){
int grade = 0;
cout<<"1 : First Grade\n";
cout<<"2 : Second Grade\n";
cout<<"3 : Third Grade\n";
cout<<"4 : Fourth Grade\n";
cout<<"5 : Fifth Grade\n";
cout<<"\nPlease select grade, use numbers 1 to 5: ";
do {
cin>>grade;
if(grade >= 1 && grade <= 5){
break;
}
else {
cout<<"\nGrade must be between 1 and 5\n";
cout<<"Invalid choice, please select correct grade: ";
}
} while(true);
return grade;
}
void createQuestions(int l, int u, int q){
int firstNum = 0, secondNum = 0;
for(int i = 1; i <= q; i++){
firstNum = l + (rand() % (u - l + 1));
secondNum = l + (rand() % (u - l + 1));
cout<<setw(2)<<i<<".";
if(rand() % 2 == 0){
cout<<" ("<<firstNum<<" + "<<secondNum<<") = ______\t\t";;
}
else{
if(firstNum > secondNum) {
cout<<" ("<<firstNum<<" - "<<secondNum<<") = ______\t\t";
}
else{
cout<<" ("<<secondNum<<" - "<<firstNum<<") = ______\t\t";
}
}
if(i % 3 == 0){
cout<<"\n";
}
}
}
void generatePaper(int grade, int questions) {
int lowerLimit, Upperlimit;
if(grade == 1){
lowerLimit = 10;
Upperlimit = 99;
createQuestions(lowerLimit, Upperlimit, questions);
}
else if(grade == 2){
lowerLimit = 100;
Upperlimit = 999;
createQuestions(lowerLimit, Upperlimit, questions);
}
else if(grade == 3){
lowerLimit = 1000;
Upperlimit = 9999;
createQuestions(lowerLimit, Upperlimit, questions);
}
else if(grade == 4){
lowerLimit = 10000;
Upperlimit = 99999;
createQuestions(lowerLimit, Upperlimit, questions);
}
else if(grade == 5){
lowerLimit = 100000;
Upperlimit = 999909;
createQuestions(lowerLimit, Upperlimit, questions);
}
}
main(){
int grade = 0, numQuestions = 0;
grade = selectGrade();
cout<<"Enter number of questions you want to generate: ";
cin>>numQuestions;
cout<<endl;
generatePaper(grade, numQuestions);
cout<<endl;
system("pause");
}
```

]]>