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

Lab 10

The document outlines 5 tasks for a C++ programming lab. The tasks involve: 1) Determining if a shape is a rectangle or square based on length and breadth input. 2) Displaying the salary of a senior or junior salesperson based on status input. 3) Determining if a character is a vowel or not. 4) Printing a passing or failing grade message based on marks input. 5) Calculating the area of a circle if radius is positive, or printing an error if radius is negative or zero. For each task, sample code and expected output is provided.

Uploaded by

alizain889989069
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lab 10

The document outlines 5 tasks for a C++ programming lab. The tasks involve: 1) Determining if a shape is a rectangle or square based on length and breadth input. 2) Displaying the salary of a senior or junior salesperson based on status input. 3) Determining if a character is a vowel or not. 4) Printing a passing or failing grade message based on marks input. 5) Calculating the area of a circle if radius is positive, or printing an error if radius is negative or zero. For each task, sample code and expected output is provided.

Uploaded by

alizain889989069
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB 10 TASKS

1. Create a C++ program that takes the length and breadth of a shape as input. Using If-Else
structure find out whether the shape is a rectangle or a square. (Hint: if the length and
breadth of the shape are equal, it’s a square. Otherwise, it is a rectangle.)

Code:
#include <iostream>
using namespace std;
int main()
{
int l,b;
cout<<"Enter the Lenght: ";
cin>>l;
cout<<"Enter the breadth: ";
cin>>b;
if(l==b)
{
cout<<"The shape is a square"<<endl;
}
else
{
cout<<"The shape is a rectangle"<<endl;
}
return 0;
}
Output:
2. A senior salesperson is paid $400 a week; and a junior salesperson is paid $275 a week.
Write a C++ program that accepts as input the salesperson’s status in the character
variable status. If status equals ‘s’, the senior salesperson’s salary should be displayed;
otherwise, the junior person’s salary should be output.

Code:
#include <iostream>
using namespace std;
int main()
{
char var;
cout <<"Input variable: ";
cin>>var;
if(var=='s')
{
cout <<"senior salespersons salary $400"<<endl;
}
else
{
cout<<"junior salespersons salary $275"<<endl;
}
return 0;
}
Output:
3. Write a program that inputs a character as input and tells whether the entered character is
a vowel or not.

Code:
#include <iostream>
using namespace std;
int main()
{
char var;
cout <<"Input character: ";
cin>>var;
if(var=='a'||var=='e'||var=='i'||var=='o'||var=='u')
{
cout <<"This is a vowel"<<endl;
}
else
{
cout<<"This is not a vowel"<<endl;
}
return 0;
}
Output:
4. In a pass/fail course, a student passes if the marks are greater than or equal to 70 and fails
if the marks are lower. Write a C++ program that accepts marks and prints the message
“A passing grade” or “A failing Grade”, as appropriate.

Code:
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Enter the student's marks: ";
cin >> a;
if(a >= 70)
{
cout << "A passing grade" << endl;
}
else
{
cout << "A failing grade" << endl;
}
return 0;
}
Output:
5. Write a program that takes input the radius of a circle. If this radius is greater than zero,
calculate the area of the circle. If the radius is less than or equal to zero, print an Error
message that area cannot be calculated for negative values.

Code:
#include <iostream>
using namespace std;
int main()
{
int r;
cout << "Enter Radius: ";
cin >> r;
if(r>0)
{
cout << "Area of circle: "<<3.14*r*r<< endl;
}
else
{
cout << "Error" << endl;
}
return 0;
}
Output:

You might also like