#include <iostream>
#include <cstring>
class Employee {
public:
char name[100];
float salary;
Employee(const char* empName, float empSalary) {
strcpy(name, empName);
salary = empSalary;
void display() {
std::cout << "Employee Name: " << name << std::endl;
std::cout << "Employee Salary: " << salary << std::endl;
};
int main() {
Employee emp("Scott", 20000.67);
emp.display();
return 0;
}
Employee Name: Scott
Employee Salary: 20000.7
#include <iostream>
#include <string>
using namespace std;
class Employee {
private:
string name;
float salary;
string department;
public:
void getData() {
cout << "Enter Employee Name: ";
getline(cin, name);
cout << "Enter Employee Salary: ";
cin >> salary;
cin.ignore();
cout << "Enter Employee Department: ";
getline(cin, department);
} void showData() const {
cout << "\nEmployee Details:" << endl;
cout << "Name: " << name << endl;
cout << "Salary: " << salary << endl;
cout << "Department: " << department << endl;
};
int main() {
Employee emp;
emp.getData();
emp.showData();
return 0;
Enter Employee Name: RAHUL
Enter Employee Salary: 200000
Enter Employee Department: CSDS
Employee Details:
Name: RAHUL
Salary: 200000
Department: CSDS
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name; int rollno; float marks[3]; float score;
public:
void getData() {
cout << "Enter Student Name: ";
cin.ignore(); getline(cin, name);
cout << "Enter Roll Number: ";
cin >> rollno;
cout << "Enter Marks for 3 Subjects: ";
for (int i = 0; i < 3; i++) { cin >> marks[i];
score = (marks[0] + marks[1] + marks[2]) / 3.0;
} void showData() const {
cout << "Student Details:" << endl;
cout << "Name: " << name << endl;
cout << "Roll Number: " << rollno << endl;
cout << "Marks: " << marks[0] << ", " << marks[1] << ", " << marks[2] << endl;
cout << "Average Score: " << score << endl;
if (score < 40) {
cout << "Result: FAIL" << endl;
} else {
cout << "Result: PASS" << endl;
};
int main() {
Student students[10];
for (int i = 0; i < 10; i++) {
cout << "Enter details for Student " << (i + 1) << ":";
students[i].getData();
cout << "Displaying Student Records:";
for (int i = 0; i < 10; i++) {
students[i].showData();
return 0;
Student 1:
Enter name: Alice
Enter roll number: 1
Enter marks for 3 subjects: 45 55 60
Student 2:
Enter name: Bob
Enter roll number: 2
Enter marks for 3 subjects: 35 25 40
Displaying student records
Student 1:
Name: Alice
Roll Number: 1
Marks: 45 55 60
Average Score: 53.33
Status: PASS
Student 2:
Name: Bob
Roll Number: 2
Marks: 35 25 40
Average Score: 33.33
Status: FAIL
#include <iostream>
using namespace std;
int sum(int a,int b)
return a+b;
int sum(int a,int b,int c)
return a+b+c;
float sum(float a,float b)
return a+b;
int main()
int x=5,y=10,z=15;
float p=2.5 , q=3.5;
cout<<"sum of two integers :"<<sum(x,y)<<endl;
cout<<"sum of three integers :"<<sum(x,y,z)<<endl;
cout<<"sum of two floats :"<<sum(p,q)<<endl;
return 0;
}
sum of two integers :15
sum of three integers :30
sum of two floats :6
#include <iostream>
using namespace std;
class Shapes{
private:
float area;
public:
void calArea(float length,float width){
area=length*width;
cout<<"Area of rectangle :"<<area<<endl;
void calArea(float side){
area=side*side;
cout<<"Area of square :"<<area<<endl;
};
int main()
Shapes shape;
shape.calArea(5,2.5);
shape.calArea(7);
return 0;
}
Area of rectangle :12.5
Area of square :49