Programming fundamental
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
Code: case 'a': ++a;
break; case 'e': +
#include<iostrea
+e; break; case 'i':
m> ++i; break; case
'o': ++o; break;
#include<conio.h
case 'u': ++u;
break;
>
}
}
using namespace std;
cout << "\n\n\tThe Entered phrase vowels are = " <<
int main()
endl; cout << "a\t\te\t\ti\t\to\t\tu" << endl;
{
cout << a << "\t\t" << e << "\t\t" << i << "\t\t" << o << "\t\t"
int a, e, i, o, u;
<< u << endl;
a = e = i = o = u = 0;
char ch;
cout << "\t\tEnter any phrase to count vowels in it!
\n\n"; while ((ch = _getch()) != '#')
{
Output:
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;
cout << setiosflags(ios::fixed);
cout << setiosflags(ios::showpoint) <<
setprecision(2); cout << "\t\tSwitch-based
Marksheet" << endl;
cout << "Enter your maths
marks: "; cin >> maths;
maths = (maths > 100) ? -1 : maths;
cout << "Enter your English
marks: "; cin >> english;
english = (english > 100) ? -1 : english;
cout << "Enter your chemistry
marks: "; cin >> chemistry;
chemistry = (chemistry > 100) ? -1 : chemistry;
cout << "Enter your ICT marks:
"; cin >> ict;
ict = (ict > 100) ? -1 : ict;
total = maths + english + chemistry +
ict; avg = total / 4.0;
cout << "\nTotal Marks: " << total <<
endl; cout << "Average Marks: " << avg
<< endl;
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;
}
cout << "Letter Grade: " << letter_grade <<
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: