Professional Documents
Culture Documents
Semester
COMP 150 (Introduction to
Programming)
C++ Coding
Assignment 2
Submitted to:
Prof. Siddhartha Shyam Vyas
Submitted by:
Manav Babbar (300166069)
BCIS 1st Year 2nd Semester
TABLE OF CONTENTS
2 ACKNOWLEDGEMENT ii
There should be no page# in the footer section of FRONT PAGE, TABLE OF CONTENTS.
ACKNOWLEDGEMENT & CERTIFICATE OF ORIGINALITY pages will have Roman Numeral page# in
the footer section as specified in the TABLE OF CONTENTS (i) (ii)
CERTIFICATE OF ORIGINALITY must remain exactly the same as shown in the document. The name
of the student must be typed neatly with hand-signatures using a blue / black pen beside it.
Please check the ACKNOWLEDGEMENT part. However, you can modify it further by adding more
people you have connected with apart from your COMP150 professor for the assignment. The name of
the student must be typed neatly with hand-signatures using a blue / black pen beside it.
The normal page# like: 1, 2 etc. in the footer section must start from Question 1 of the ASSIGNMENT.
Also, the first question should be written completely followed by the code for the question typed neatly
and legibly. Once the code part is done, then also put the screen-shot of the output below it. Every
question of the assignment must start from a fresh new page.
If you have consulted any organization, you should have a good explanation of how efficient is the
algorithm that you are typing for the program compared to what is done and shown to you all in the
class. Also, you can always give a brief overview of the organization consulted and then start the
Question 1 from the fresh new page for the assignment. Kindly staple the visiting cards of people if
consulted any, with regard to your assignment. If visiting cards aren't available, kindly mention the
following: Name of the person, Telephone/ cell number, email-id, designation, organization name
REFERENCES must start from a new page. No page# required in the footer section of REFERENCES
page. REFERENCES must be in APA Style format. If no references are there, then it must be written in
the “REFERENCES” section as – NO REFERENCES AVAILABLE FOR THIS ASSIGNMENT.
FONT STYLE: is your choice but must look professional, neat & tidy.
Assignments shall be communicated to the students in the class and via email. The due date of
assignment submission has been mentioned in the course outline.
Answers: -
#include<iostream.h>
#include<conio.h>
int max (int x,int y);
void main()
{
clrscr();
int var1, var2, fetch;
cout<<"Enter the 1st number: ";
cin>>var1;
cout<<"Enter the 2nd number: ";
cin>>var2;
fetch=max(var1 , var2);
cout<<" The maximum number is : "<<fetch;
getch();
}
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
2. WAP to perform a four-function calculator using 'nested if-else' / 'switch-case'. Create a different user-
defined functions for the following:
Take the user input in main() function.
addition() - for calculating addition two numbers
difference() - for calculating the difference of two numbers
product() - for calculating the product of two numbers
division() - for calculating the division of two numbers.
All these user-defined functions must return a value to main() function for printing the result
#include<iostream.h>
#include<conio.h>
#include<process.h>
int add(int g, int h);
int sub(int g, int h);
int prod(int g, int h);
float div(int g, int h);
void main()
{
clrscr();
int no1, no2, draw, option;
char answer;
do
{
clrscr();
cout<<"Enter the 1st Number: ";
cin>>no1;
cout<<"Enter the 2nd Number: ";
cin>>no2;
cout<<"\n\n\t\t\t Menu ";
cout<<"\n 1. Addition ";
cout<<"\n 2. Subtraction ";
cout<<"\n 3. Multiplication ";
cout<<"\n 4. Division ";
cout<<"\n 5. Exit ";
cout<<"\n Enter any choice ";
cin>>option;
switch(option)
{
{
case 1:draw=add(no1 , no2);
break;
}
{
case 2:draw=sub(no1 , no2);
break;
}
{
case 3:draw=prod(no1 , no2);
break;
}
{
case 4:draw=div(no1 , no2);
break;
}
{
case 5: cout<<"Exit";
getch();
exit(0);
}
{
default: cout<<"Wrong Choice";
goto i;
}
}
cout<<"The Result of "<<no1<<" & "<<no2<<" is: "<<draw;
i:cout<<"\n Do you want to continue : ";
answer=getch();
}
while((answer=='y')||(answer=='Y'));
getch();
}
int add(int g, int h)
{
return g+h;
}
int sub(int g, int h)
{
return g-h;
}
int prod(int g, int h)
{
return g*h;
}
float div(int g, int h)
{
return float(g/h);
}
result
#include<iostream.h>
#include<conio.h>
int sum_of_even(int m);
int sum_of_odd(int m);
void main()
{
clrscr();
int h,i,even,odd;
even=odd=0;
cout<<"\n Enter the limit : ";
cin>>h;
even=sum_of_even(h);
odd=sum_of_odd(h);
the result
#include<iostream.h>
#include<conio.h>
int sum(int x,int y);
void main()
{
clrscr();
int var1,var2,grab;
cout<<"Enter the 1st Number: ";
cin>>var1;
cout<<"Enter the 2nd Number: ";
cin>>var2;
grab=sum(var1,var2);
cout<<"\n The addition of 2 Numbers "<<var1<<" & "<<var2<<" is : "<<grab;
getch();
}
int sum(int x,int y)
{
int add=0;
add=x+y;
return add;
}
#include<iostream.h>
#include<conio.h>
void print_days(int choice);
void main()
{
clrscr();
int d;
cout<<"Enter any no btw 1-7: ";
cin>>d;
print_days(d);
getch();
}
void print_days(int choice)
{
switch(choice)
{
case 1:
{
cout<<" Day is Monday ";
break;
}
case 2:
{
cout<<" Day is Tuesday ";
break;
}
case 3:
{
cout<<" Day is Wednesday ";
break;
}
case 4:
{
cout<<" Day is Thursday ";
break;
}
case 5:
{
cout<<" Day is Friday ";
break;
}
case 6:
{
cout<<" Day is Saturday ";
break;
}
case 7:
{
cout<<" Day is Sunday ";
break;
}
default:
{
cout<<" Wrong Choice ";
}
}