/*Write a C++ program to implement a class called Date that has private member variables
for day, month, and year. Include member functions to set and get these variables, as well
as to validate if the date is valid.*/
#include <iostream>
using namespace std;
class Date {
private:
int day, month, year;
public:
void setDate(int d, int m, int y) {
day = d; month = m; year = y;
bool isValid() {
if (month < 1 || month > 12) return false;
if (day < 1 || day > 31) return false;
// Simple check for months with 30 days
if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) return false;
// Simple Feb check
if (month == 2 && day > 29) return false;
return true;
}
void getDate() {
cout << day << "/" << month << "/" << year << (isValid() ? " (Valid)" : " (Invalid)") << endl;
};
int main() {
Date d1;
[Link](31, 4, 2024); // April has 30 days
[Link]();
return 0;
}
/*Write a C++ program to implement a class called Student that has private member
variables for name, class, roll number, and marks. Include member functions to calculate
the grade based on the marks and display the student's information. Also print maximum
mark with help of a Maxi() function.*/
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
int className, rollNum;
float marks;
public:
void setData(string n, int c, int r, float m) {
name = n; className = c; rollNum = r; marks = m;
char calculateGrade() {
if (marks >= 90) return 'A';
else if (marks >= 75) return 'B';
else if (marks >= 50) return 'C';
else return 'F';
}
void display() {
cout << name << "\t" << rollNum << "\t" << marks << "\t" << calculateGrade() << endl;
float getMarks() { return marks; }
};
void Maxi(Student s[], int n) {
float maxM = 0;
for(int i = 0; i < n; i++) {
if(s[i].getMarks() > maxM) maxM = s[i].getMarks();
cout << "Maximum Mark: " << maxM << endl;
int main() {
Student s[2];
s[0].setData("Mehedi", 60, 101, 85);
s[1].setData("hasan", 61, 102, 92);
cout << "Name\tRoll\tMarks\tGrade" << endl;
s[0].display();
s[1].display();
Maxi(s, 2); return 0;}
/*Write a program that would print the information (name, year of joining, salary, address) of
three employees by creating a class named 'Employee'. The output should be as
follows:
Name Year of joining Address
Robert 1994 64C-WallsStreat
Sam 2000 68D-WallsStreat
John 1999 26B- WallsStreat*/
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
string name, address;
int year;
void setData(string n, int y, string a) {
name = n; year = y; address = a;
void display() {
cout << name << "\t\t" << year << "\t\t" << address << endl;
};
int main() {
Employee e[3];
e[0].setData("Robert", 1994, "64C-WallsStreat");
e[1].setData("Sam", 2000, "68D-WallsStreat");
e[2].setData("John", 1999, "26B-WallsStreat");
cout << "Name\t\tYear of Joining\tAddress" << endl;
for(int i=0; i<3; i++) e[i].display();
return 0;
}
#include <iostream>
using namespace std;
class Bill {
int units;
float total;
public:
void get() {
cout << "Enter units consumed: ";
cin >> units;
void calc_bill() {
if (units <= 100) total = units * 5;
else if (units <= 200) total = (100 * 5) + (units - 100) * 7;
else total = (100 * 5) + (100 * 7) + (units - 200) * 9;
void put() {
cout << "Total Bill: " << total << " Taka" << endl;
};
int main() {
Bill b;
[Link]();
b.calc_bill();
[Link]();
return 0;