Assignment No. 2
Semester: SPRING 2013
CS410 – VISUAL PROGRAMMING
Total Marks: 20
Due Date: 6th May, 2013
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/From students).
You should consult recommended books to clarify your concepts and can also put queries on MDB.
Objective
To understand the concepts of Macros, Switch Statement and Bitwise Operators.
Software (s) Used to develop Assignment
Visual C++ 6.0 And MS Word
Language
C/C++
Assignment Submission Instructions
Assignment should be submitted in a zipped folder named “VU-RollNo” format, which includes
following files:
→ Question No. 1 should be in “Question1.cpp” format.
→ Question No. 2 should be in “Question2.doc” format.
Assignment
Marks Distribution:
10+10= 20
Background:
XYZ Technologies
XYZ Technologies is a leading international provider of automated and IT enabled solutions catering to businesses across various verticals around the globe. Since its inception in 1995, XYZ has regimented itself being committed to deliver the best software solutions. XYZ has ever since used highly experienced resources in analysis, development, quality assurance, and implementation to provide a wide range of high-quality consulting services and cost-effective development of customized application software. XYZ’s worldwide domain and subject matter expertise, proven track record and the capability to act as solution integrators can give you a truly cost-effective solution thatnot only meets, but surpasses your needs.
Scenario:
XYZ –Prohibition Period For Win32 Programmers
During the recruitment session the HR department of XYZ company has selected some competent people. After the interview session some of them have been hired.As per company policy the starting 1 month will be probation period for them in which their performance will be judged through some practical tasks. Then successful candidates will be promoted, else fired.
Evaluation:
Now being selected, you need to perform the given task. The task consists of 2 parts; the first is about developing a code and second issolving certain expressions.
Part 1:
Write a program which performs basic four mathematical operations i.e. Addition, Subtraction, Multiplication and Division.
1. Develop a function named “menu”. The users can select any option from the given menu. When user will press ‘A’ it will perform Addition and so on. Use switch statement to achieve this functionality.
2. To perform operations (Addition,Subtraction, Multiplication and Division) you have to define macros.
Note: A video demo is also attached toillustrate about the other requirements and output format of the program.
Part 2:
Consider the following code snippet:
unsigned int x, y, z, r;
x=0xA502;
y=0xB610;
z=0x540C;
First convert the x, y, z values into binary form and then solve the following bitwise expressions.
1. x&y=?
2. y|z=?
3. r=(x<<2) + (y>>4)=?
4. z^r=?
Note: You have to solve each expression like this
x= (Binary value)
y= (Binary value)
(x&y)= (Binary value)
= (Convert final output into Hex Value)
Lectures Covered: This Assignment covers Lecture No.5 – Lecture No. 7
Deadline: Your assignment must be uploaded on or before 06th May, 2013.
#include
#include
#include
#include
using namespace std;
//Macros
#define Add(x,y) (x+y)
#define Subtract(x,y)(x-y)
#define Mul(x,y)(x*y)
#define Div(x,y)(x/y)
//All Function prototypes
int Addition(int,int);
int Subtraction(int,int);
int Multiplication(int,int);
int Division(int,int);
int main(){
char t;
MAINMENU:
cout <<"\tTo Perform Addition"<<setw(20)<<"Press A"<<endl;
cout <<"\tTo Perform Subtraction"<<setw(17)<<"Press S"<<endl;
cout <<"\tTo Perform Multiplication"<<setw(14)<<"Press M"<<endl;
cout <<"\tTo Perform Division"<<setw(20)<<"Press D"<<endl;
cout <<"\tTo Exit"<<setw(32)<<"Press X"<<endl;
cout <>t ;
switch(t){
int firstnum, secnum;
case ‘A’:
cout <> firstnum;
cout <> secnum;
cout <<"\t\tResult is \t"<< Addition(firstnum,secnum) << endl;
//Sub Menu
cout << "To exit\t\t\t\tX" << endl;
cout <<"Main Menu\t\t\tB" << endl;
cout <<"Enter your choice\t\t\t";
goto SUBMENU;
break;
case 'S':
cout <> firstnum;
cout <> secnum;
cout <<"\t\tResult is \t"<< Subtraction(firstnum,secnum) << endl;
//Sub Menu
cout << "To exit\t\t\t\tX" << endl;
cout <<"Main Menu\t\t\tB" << endl;
cout <<"Enter your choice\t\t\t";
goto SUBMENU;
break;
case 'M':
cout <> firstnum;
cout <> secnum;
cout <<"\t\tResult is \t"<<Multiplication(firstnum,secnum) << endl;
//Sub Menu
cout << "To exit\t\t\t\tX" << endl;
cout <<"Main Menu\t\t\tB" << endl;
cout <<"Enter your choice\t\t\t";
goto SUBMENU;
break;
case 'D':
cout <> firstnum;
again:
cout <> secnum;
//check if denominator is ZERO
if(secnum == 0){
cout << "Zero in denominator is not allowed" << endl;
goto again;
}
cout <<"\t\tResult is \t"<<Division(firstnum,secnum) << endl;
//Sub Menu
cout << "To exit\t\t\t\tX" << endl;
cout <<"Main Menu\t\t\tB" << endl;
cout <<"Enter your choice\t\t\t";
goto SUBMENU;
break;
case 'B':
goto MAINMENU;
break;
case 'X':
exit(0);
break;
default:
cout <<"\t\t\tYou have entered wrong option" << endl;
//Sub Menu
cout << "To exit\t\t\t\tX" << endl;
cout <<"Main Menu\t\t\tB" << endl;
cout <<"Enter your choice\t\t\t";
goto SUBMENU;
}
return 0;
}
//Arithmatic Functions
int Addition(int a, int b){
int result;
result = Add(a,b);
return result;
}
int Subtraction(int a, int b){
int result;
result = Subtract(a,b);
return result;
}
int Multiplication(int a, int b){
int result;
result = Mul(a,b);
return result;
}
int Division(int a, int b){
int result;
result = Div(a,b);
return result;
}
x=0xA502; 1010010100000010
y=0xB610; 1011011000010000
z=0x540C; 0101010000001100
(x&y)=(1010010000000000)=(0xA400)
(Y or z)=( 1111 011000011100)=( 0xF61C)
r=(x2) + (y>>4)=?(11000111101101001)=(0x18F69)
z^r=(11101101101100101)=(0x1DB65)