0% found this document useful (0 votes)
17 views8 pages

Cs Final Submission 55

This document contains the solutions to 4 programming tasks assigned as part of a lab for a Programming Fundamentals course. The tasks involve writing C++ programs to: 1) check if a triangle is valid given three side lengths as input, 2) find the tallest of three students given their heights as input, 3) print the number of days in a given month based on a number input, and 4) find the roots of a quadratic equation given coefficients as input. The document provides the source code and output for each task solved using techniques like nested if statements and switch cases.

Uploaded by

Khadija Müghål
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Cs Final Submission 55

This document contains the solutions to 4 programming tasks assigned as part of a lab for a Programming Fundamentals course. The tasks involve writing C++ programs to: 1) check if a triangle is valid given three side lengths as input, 2) find the tallest of three students given their heights as input, 3) print the number of days in a given month based on a number input, and 4) find the roots of a quadratic equation given coefficients as input. The document provides the source code and output for each task solved using techniques like nested if statements and switch cases.

Uploaded by

Khadija Müghål
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Faculty of Computing

[Programming Fundamentals]
Lab No 5 solution

Course Instructor: Ma’am Mehvish


Lab Instructor: Ma’am Hafsah Mahmood
Task 1: Write a program to check whether triangle is valid or not if sides are taken as input
from user. Use Nested If statements.

SOURCE CODE
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter side a"<<endl;
cin>>a;
cout<<"Enter side b"<<endl;
cin>>b;
cout<<"Enter side c"<<endl;
cin>>c;
if(a+b>c){cout<<"a+b>c"<<endl;
if(a+c>b){
cout<<"a+c>b"<<endl;
if(b+c>a){
cout<<"b+c>a"<<endl;
cout<<"All the three conditions satisfied"<<endl;
cout<<"Triangle is valid"<<endl;
}
}
else{cout<<"All the three conditions do not satisfied"<<endl;
cout<<"Triangle is not valid";
}
}
return 0;
}
OUTPUT

Task 2: Write a Program to find the tallest student among 3 students. Note the heights must be
taken as input from user. Use Nested if statements.
Task 3: Write a C++ program print total number of days in a month using switch case. The
number of the month should be taken as input from user.

Source code
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter month number";
cin>>a;
switch(a)
{case 1:
cout <<"JANUARY has 31 days";
break;
case 2:
cout <<"FEBRUARY has 28 days";
break;
case 3:
cout <<"MARCH has 31 days";
break;
case 4:
cout <<"APRIL has 30 days";
break;
case 5:
cout <<"MAY has 31 days";
break;
case 6:
cout <<"JUNE has 30 days";
break;
case 7:
cout <<"JULY has 31 days";
break;
case 8:
cout <<"AUGUST has 31 days";
break;
case 9:
cout <<"SEPTEMBER has 30 days";
break;
case 10:
cout <<"OCTOBER has 31 days";
break;
case 11:
cout <<"NOVEMBER has 30 days";
break;
case 12:
cout <<"DECEMBER has 31 days";
break;
}
return 0;
}
Output

Task 4: Write program to find all roots of a quadratic equation using switch case. The
coefficients of the equation should be taken from user.
Source code
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,c;
int discriminant;
cout<<"number 1 ";
cin>>a;
cout<<"number 2 ";
cin>>b;
cout<<"number 3 ";
cin>>c;
discriminant=b*b-4*a*c;
switch(discriminant)
{case positive dicriminant:
cout <<"discrminant is positive";
break;
case negative discriminant:
cout <<"discriminat is negative";
break;
}
return 0;
}

You might also like