0% found this document useful (0 votes)
8 views3 pages

C++ Lab Assignment Part1

The document contains multiple C++ programs demonstrating basic functionalities such as displaying a message, calculating the area of a circle, converting Celsius to Fahrenheit, finding the HCF and LCM of two numbers, replacing 'dog' with 'cat' in a string, and defining a student class to manage student data. Each program includes user input and output functionalities. The examples illustrate fundamental programming concepts in C++.

Uploaded by

brishalraj2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

C++ Lab Assignment Part1

The document contains multiple C++ programs demonstrating basic functionalities such as displaying a message, calculating the area of a circle, converting Celsius to Fahrenheit, finding the HCF and LCM of two numbers, replacing 'dog' with 'cat' in a string, and defining a student class to manage student data. Each program includes user input and output functionalities. The examples illustrate fundamental programming concepts in C++.

Uploaded by

brishalraj2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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;
}

You might also like