C++ & Java : Assignment 1
These are the programs which are requested in assignment 1. I have executed them all and they are perfectly runnning and giving correct output. However, I am not 100% sure that these are what Miss Gauri wants.
There was a small problem while copy pasting howevr, the progtam is executable. Wile writing in assg, after every semicolon, continue on new line where it is not done so.
1) Calculator program
#include
#include
#include
#include
int sum(int a, int b)
{
int m;
m=a+b;
return m;
}
int diff(int a, int b)
{
int m;
m=a-b;
return m;
}
int prod(int a, int b)
{
int m;
m=a*b;
return m;
}
int division(int a, int b)
{
int m;
m=a/b;
return m;
}
int read()
{
int a,b;
cout << "Enter 1st operand ";
cin >> a;
cout << "Enter 2nd operand ";
cin >> b;
}
void choice()
{
int a,b,c,m;
cout << "\nEnter 1 for addition\n";
cout << "Enter 2 for sutraction\n";
cout << "Enter 3 for product\n";
cout << "Enter 4 for division\n";
cout << "Enter choice";
cin >> c;
if (c==1)
m=sum(a,b);
else if (c==2)
m=diff(a,b);
else if (c==3)
m=prod(a,b);
else if (c==4)
m=division(a,b);
else
cout << "Invalid choice";
cout << "\nSolution "<< m;
}
int main()
{
read();
choice();
getch();
return 0;
}
2) Employee Total Salary program
#include
#include
#include
#include
void getdata()
{
char name[30];
int basic_sal;
float total_sal;
cout << "Enter name of employee: ";
cin >> name;
cout << "\nEnter basic salary: ";
cin >> basic_sal;
cout << "\n\nName: " << name << "\n";
cout << "Basic Salary: " << basic_sal <<"\n";
total_sal=basic_sal + (basic_sal*0.2) + (basic_sal*0.15) + (basic_sal*0.1);
cout << "\nTotal Salary = " << total_sal;
}
int main()
{
getdata();
getch();
return 0;
}
3)Right Angled Triangle program
#include
#include
#include
#include
void triangle(int a, int b, int c)
{
int m,n;
if((a>b)&&(a>c))
{
m=a*a;
n=(b*b)+(c*c);
}
else if((b>a)&&(b>c))
{
m=b*b;
n=(a*a)+(c*c);
}
else
{
m=c*c;
n=(a*a)+(b*b);
}
if(m==n)
cout << "\nTriangle is a right angled triangle";
else
cout << "\nTriangle is not a right angled triangle";
}
int main()
{
int a,b,c;
cout << "Enter 1st of the triangle:";
cin >> a;
cout << "\nEnter 2nd of the triangle:";
cin >> b ;
cout << "\nEnter 3rd of the triangle:";
cin >> c ;
triangle(a,b,c);
getch();
return 0;
}
These are the three programs and I am sure they will help you. If you have any comments or doubts you can post here.
I will post the 2nd assignment by tommorow night.
There was a small problem while copy pasting howevr, the progtam is executable. Wile writing in assg, after every semicolon, continue on new line where it is not done so.
1) Calculator program
#include
#include
#include
#include
int sum(int a, int b)
{
int m;
m=a+b;
return m;
}
int diff(int a, int b)
{
int m;
m=a-b;
return m;
}
int prod(int a, int b)
{
int m;
m=a*b;
return m;
}
int division(int a, int b)
{
int m;
m=a/b;
return m;
}
int read()
{
int a,b;
cout << "Enter 1st operand ";
cin >> a;
cout << "Enter 2nd operand ";
cin >> b;
}
void choice()
{
int a,b,c,m;
cout << "\nEnter 1 for addition\n";
cout << "Enter 2 for sutraction\n";
cout << "Enter 3 for product\n";
cout << "Enter 4 for division\n";
cout << "Enter choice";
cin >> c;
if (c==1)
m=sum(a,b);
else if (c==2)
m=diff(a,b);
else if (c==3)
m=prod(a,b);
else if (c==4)
m=division(a,b);
else
cout << "Invalid choice";
cout << "\nSolution "<< m;
}
int main()
{
read();
choice();
getch();
return 0;
}
2) Employee Total Salary program
#include
#include
#include
#include
void getdata()
{
char name[30];
int basic_sal;
float total_sal;
cout << "Enter name of employee: ";
cin >> name;
cout << "\nEnter basic salary: ";
cin >> basic_sal;
cout << "\n\nName: " << name << "\n";
cout << "Basic Salary: " << basic_sal <<"\n";
total_sal=basic_sal + (basic_sal*0.2) + (basic_sal*0.15) + (basic_sal*0.1);
cout << "\nTotal Salary = " << total_sal;
}
int main()
{
getdata();
getch();
return 0;
}
3)Right Angled Triangle program
#include
#include
#include
#include
void triangle(int a, int b, int c)
{
int m,n;
if((a>b)&&(a>c))
{
m=a*a;
n=(b*b)+(c*c);
}
else if((b>a)&&(b>c))
{
m=b*b;
n=(a*a)+(c*c);
}
else
{
m=c*c;
n=(a*a)+(b*b);
}
if(m==n)
cout << "\nTriangle is a right angled triangle";
else
cout << "\nTriangle is not a right angled triangle";
}
int main()
{
int a,b,c;
cout << "Enter 1st of the triangle:";
cin >> a;
cout << "\nEnter 2nd of the triangle:";
cin >> b ;
cout << "\nEnter 3rd of the triangle:";
cin >> c ;
triangle(a,b,c);
getch();
return 0;
}
These are the three programs and I am sure they will help you. If you have any comments or doubts you can post here.
I will post the 2nd assignment by tommorow night.
0 Comments:
Post a Comment
<< Home