Pps 2
Pps 2
class GreatestFinder {
private:
double num1, num2, num3;
public:
// Constructor to initialize the numbers
GreatestFinder(double n1, double n2, double n3) {
num1 = n1;
num2 = n2;
num3 = n3;
}
return greatest;
}
};
int main() {
double num1, num2, num3;
return 0;
}
Q2
#include <iostream>
using namespace std;
class FactorialCalculator {
private:
int number;
public:
FactorialCalculator(int n) {
number = n;
}
long long calculateFactorial() {
if (number < 0) {
cout << "Factorial is not defined for negative numbers." << endl;
return -1;
}
long long factorial = 1;
for (int i = 2; i <= number; ++i) {
factorial *= i;
}
return factorial;
}
};
int main() {
int num;
FactorialCalculator calculator(num);
if (factorial != -1)
cout << "Factorial of " << num << " is: " << factorial << endl;
return 0;
}
Q3
#include <iostream>
using namespace std;
int main() {
int num, smallest1, smallest2, largest1, largest2;
// Input the remaining numbers and update smallest1, smallest2, largest1, and largest2
for (int i = 3; i <= num; ++i) {
int temp;
cout << "Enter element " << i << ": ";
cin >> temp;
cout << "Two smallest elements: " << smallest1 << " and " << smallest2 << endl;
cout << "Two largest elements: " << largest1 << " and " << largest2 << endl;
return 0;
}
Q4
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Student {
private:
string name;
int rollNumber;
float cgpa;
public:
Student(string n, int roll, float cg) {
name = n;
rollNumber = roll;
cgpa = cg;
}
string getName() const {
return name;
}
int main() {
int numStudents;
cout << "Enter the number of students: ";
cin >> numStudents;
vector<Student> students;
return 0;
}
Q5
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Employee {
private:
int id;
string name;
int daysWorked;
public:
// Constructor to initialize employee details
Employee(int _id, const string& _name, int _daysWorked) : id(_id), name(_name), daysWorked(_daysWorked) {}
// Getter methods to access private member variables
int getID() const { return id; }
const string& getName() const { return name; }
int getDaysWorked() const { return daysWorked; }
float getTotalSalary() const { return daysWorked * 1000; } // Assuming salary is 1000 rupees per day
};
int main() {
int numEmployees;
vector<Employee> employees;
cout << "\nEnter details for employee " << i + 1 << ":" << endl;
cout << "Employee ID: ";
cin >> id;
cout << "Employee Name: ";
cin.ignore();
getline(cin, name);
cout << "Number of Days Worked: ";
cin >> daysWorked;
return 0;
}