Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ using namespace std;


/* Solution */
class Book{
private:
string title = "";
string author = "";
int year = 0;
string ISBN = "";
public:
void setBookDetails(string titleP, string authorP, int yearP, string ISBNP){
title = titleP;
author = authorP;
year = yearP;
ISBN = ISBNP;
}
void displayBookDetails(){
cout << "title: " << title << endl;
cout << "author: " << author << endl;
cout << "year: " << year << endl;
cout << "ISBN: " << ISBN << endl;
}
};



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,45 @@ using namespace std;


/* Solution */

class Employee{
private:
int Id;
string name;
string designation;
double salary;
public:
Employee(){
Id = 0;
name = "";
designation = "";
salary = 0.0;
}
Employee(int IdP, string nameP, string designationP, double salaryP){
Id = IdP;
name = nameP;
designation = designationP;
salary = salaryP;
}
void setID(int idp){
Id = idp;
}
void setName(string nameparam){
name = nameparam;
}
void setDesignation(string deparam){
designation = deparam;
}
void setSalary(double salaryparam){
salary = salaryparam;
}
void displayDetails(){
cout << "Id number: " << Id << endl;
cout << "name: " << name << endl;
cout << "designation: " << designation << endl;
cout << "salary: " << salary << endl;
}

};


int main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ class BankAccount {
// Constructor
BankAccount(int accountNumber, const string &holderName, double initialBalance) {
// TODO: Initialize member variables
this->accountNumber = accountNumber;
this->holderName = holderName;
balance = initialBalance;
}

// Member functions

// TODO: Implement member functions for deposit, withdraw, and check balance
void deposit(double amount1){

balance = balance + amount1;
}
void withdraw(double amount2){
balance = balance - amount2;
}
void checkBalance() const{
cout << "Balance is: " << balance << endl;
}

};


Expand All @@ -55,6 +70,11 @@ int main() {
This exercise will help you practice encapsulation and understand how to hide
implementation details while exposing a controlled interface to the users of your class!
*/
BankAccount account1(1, "Huseyn Aghazada", 550.5);
account1.checkBalance();
account1.deposit(12.5);
account1.withdraw(26.7);
account1.checkBalance();

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,46 @@ class Employee {

public:
// TODO: Implement setters and getters
void setname(const string& name){
this->name = name;
}
void setage(int age){
this->age = age;
}
void setPosition(const string& position){
this->position = position;
}
void setSalary(double salary){
this->salary = salary;
}
string getname() const{
return name;
}
int getage() const{
return age;
}
string getPosition() const{
return position;
}
double getSalary() const{
return salary;
}

};


int main() {

// TODO: Test the Employee class by creating an object, setting attributes, and getting attribute values

Employee employee1;
employee1.setage(26);
employee1.setname("Huseyn");
employee1.setPosition("Ceo");
employee1.setSalary(3625);
cout << "employee's name: " << employee1.getname() << endl;
cout << "employee's age: " << employee1.getage() << endl;
cout << "employee's position: " << employee1.getPosition() << endl;
cout << "employee's salary: " << employee1.getSalary() << endl;
return 0;
}