Q1: Display Message
#include <iostream>
using namespace std;
int main() {
cout << "Welcome to BCE Bakhtiyarpur" << endl;
return 0;
}
Q2(a): Area of Circle
#include <iostream>
using namespace std;
int main() {
float radius, area;
cout << "Enter radius of the circle: ";
cin >> radius;
area = 3.1416 * radius * radius;
cout << "Area of Circle: " << area << endl;
return 0;
}
Q2(b): Celsius to Fahrenheit
#include <iostream>
using namespace std;
int main() {
float celsius, fahrenheit;
cout << "Enter temperature in Celsius: ";
cin >> celsius;
fahrenheit = (celsius * 9 / 5) + 32;
cout << "Temperature in Fahrenheit: " << fahrenheit << endl;
return 0;
}
Q3: HCF and LCM
#include <iostream>
using namespace std;
int main() {
int a, b, hcf, lcm, temp1, temp2;
cout << "Enter two numbers: ";
cin >> a >> b;
temp1 = a;
temp2 = b;
while (temp2 != 0) {
int temp = temp2;
temp2 = temp1 % temp2;
temp1 = temp;
}
hcf = temp1;
lcm = (a * b) / hcf;
cout << "HCF = " << hcf << ", LCM = " << lcm << endl;
return 0;
}
Q4: Replace 'dog' with 'cat'
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cout << "Enter a string: ";
getline(cin, str);
size_t pos;
while ((pos = str.find("dog")) != string::npos) {
str.replace(pos, 3, "cat");
}
cout << "Modified string: " << str << endl;
return 0;
}
Q6: Student Class
#include <iostream>
#include <string>
using namespace std;
class STUDENT {
string Sname;
int Marks[5];
int Total;
int Tmax;
public:
void Assign() {
cout << "Enter Student Name: ";
cin >> Sname;
cout << "Enter 5 subject marks: ";
Total = 0;
for (int i = 0; i < 5; i++) {
cin >> Marks[i];
Total += Marks[i];
}
Tmax = 500;
}
void Compute() {
float avg = Total / 5.0;
cout << "Average Marks: " << avg << endl;
}
void Display() {
cout << "Name: " << Sname << "\nTotal: " << Total << "\nMax: " << Tmax << endl;
}
};
int main() {
STUDENT s;
s.Assign();
s.Compute();
s.Display();
return 0;
}