Programming Fundamental Lab 2-9
Programming Fundamental Lab 2-9
lab no 02
Objective:
To write a code to calculate area
To input radius and calculate area
Code:
we will write
#include
<iostream> using
namespace std;
int main() {
float A, radius;
cout << "Enter radius" <<
endl; cin >> radius;
A = 3.14 * (radius * radius);
cout << "The Area = " << A <<
endl; return 0;
}
Output:
Lab no 06
Objective
To write a code to tell us no of vowels in a phrase
To write a code to count no of vowels
Lab no 07
Objective
To make another marksheet
To make another marksheet but using
switch Code:
#include
<iostream>
#include <iomanip>
using namespace
std;
int main() {
int maths, english, chemistry, ict,
char letter_grade;
switch (static_cast<int>(avg) /
10) { case 10:
case 9:
cout << "Excellent job" <<
endl; letter_grade = 'A';
break
; case 8:
cout << "Good work" <<
endl; letter_grade = 'B';
break
; case 7:
cout << "Good" <<
endl; letter_grade =
'C'; break;
case 6:
cout << "Passed but need improvement" <<
endl; letter_grade = 'D';
break
; case 5:
case 4:
case 3:
case 2:
case 1:
cout << "Try again next time" <<
endl; letter_grade = 'F';
break
;
default:
cout << "Wrong input" <<
endl; return 0;
}
endl; return 0;
}
Output:
Lab no 08
Objective
To write a code to identify which alphabet user
typed Code
#include
<iostream> using
int main() {
char alphabet;
cout << "Please enter an alphabet from a to f" <<
endl; cin >> alphabet;
switch (alphabet)
{ case 'a':
cout << "You entered a" <<
endl; break;
case 'b':
cout << "You entered b" <<
endl; break;
case 'c':
cout << "You entered c" <<
endl; break;
case 'd':
cout << "You entered d" <<
endl; break;
case 'e':
cout << "You entered e" <<
endl; break;
case 'f':
cout << "You entered f" <<
endl; break;
default:
cout << "Invalid input" << endl;
}
return 0;
}
Output
Lab no 09
Objective:
To write a code to tell us the day of
week Code
#include
<iostream> using
namespace std;
int main() {
enum{mon=1, tue =2, wed=3, thur=4,
fri=5,sat=6,sun=7}; int day;
cout<<"enter day of
week"<<endl; cin>>day;
switch ( day )
{
case mon:
cout<<"Its
Monday"<<endl;break; case
tue:
cout<<"Its
tuesday"<<endl;break; case
wed:
cout<<"Its
wednessday"<<endl;break; case
thur:
cout<<"Its
thursday"<<endl;break; case
fri:
cout<<"Its
friday"<<endl;break; case
sat:
cout<<"Its
saturday"<<endl;break; case
sun:
Output: