Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignments (1,2,3) #7

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
49 changes: 49 additions & 0 deletions Mehdi/Assignments 1/CH2/CH2-19.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int i1, i2, i3;

int max(int num1, int num2, int num3) // finding the maximum of three numbers.
{
int result = num1;
if (num2 > num1)
result = num2;
if (num3 > result)
result = num3;
return result;
}
int min(int num1, int num2, int num3) // finding the minimum of three numbers.
{
// local variable declaration
int result = num1;

if (num2 < num1)
result = num2;
if (num3 < result)
result = num3;
return result;
}



int main()
{
cout << "Please Enter First Integer:" <<endl;
cin >> i1;
cout << "Please Enter Second Integer:" <<endl;
cin >> i2;
cout << "Please Enter Third Integer:" <<endl;
cin >> i3;


cout << "Sum is "<< i1+i2+i3 <<endl;
cout << "Average is "<< (i1+i2+i3)/3.0 <<endl;
cout << "Product is "<< i1*i2*i3 <<endl;
cout << "Smallest is "<< min(i1,i2,i3) <<endl;
cout << "Largest is "<< max(i1,i2,i3) <<endl;


}
29 changes: 29 additions & 0 deletions Mehdi/Assignments 1/CH2/CH2-24.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int num1;


string odd_even(int num1) // Recognize the odd or even numbers
{
string odd = {"The number is odd."};
string even = {"The number is even."};

if (num1%2==0)
return even;
else
return odd;
}



int main()
{
cout << "Please enter an integer" << endl;
cin >> num1;
cout << odd_even(num1) << endl;

}
27 changes: 27 additions & 0 deletions Mehdi/Assignments 1/CH2/CH2-25.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int num1, num2;


string multiple(int num1, int num2) {
string multiple = {"The first number is a multiple of the second number."};
string not_multiple = {"The first number is not a multiple of the second number."};

if (num1%num2==0)
return multiple;
else
return not_multiple;
}

int main()
{
cout << "Please enter the first number" << endl;
cin >> num1;
cout << "Please enter the second number" << endl;
cin >> num2;
cout << multiple(num1, num2) << endl;
}
26 changes: 26 additions & 0 deletions Mehdi/Assignments 1/CH2/CH2-28.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int num;


int main()
{
cout << "Enter a five-digit number: ";
cin >> num;

// split digits
cout << num / 10000 << " ";
num = num % 10000;
cout << num / 1000 << " ";
num = num % 1000;
cout << num / 100 << " ";
num = num % 100;
cout << num / 10 << " ";
num = num % 10;
cout << num << endl;

}
15 changes: 15 additions & 0 deletions Mehdi/Assignments 1/CH3/Account.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>
using namespace std;

class Account
{
public:
Account(int);
void credit(int);
void debit(int);
int getBalance();
private:
int account_balance;
};
18 changes: 18 additions & 0 deletions Mehdi/Assignments 1/CH3/CH3-11-main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
using namespace std;

// function main begins program execution
int main()
{
// create two GradeBook objects
GradeBook gradeBook1("CS101 Introduction to C++ Programming", "John");
GradeBook gradeBook2("CS102 Data Structures in C++", "John");

// display initial value of courseName for each GradeBook
gradeBook1.displayMessage();

cout << "\ngradeBook1 created for course: " << gradeBook1.getCourseName() << " Instructor: " << gradeBook1.getInstructorName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName() << " Instructor: " << gradeBook1.getInstructorName()
<< endl;
} // end main
44 changes: 44 additions & 0 deletions Mehdi/Assignments 1/CH3/CH3-11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


#include <iostream>
#include "GradeBook.h"
using namespace std;


GradeBook::GradeBook(string name, string instrctor)
{
setCourseName(name);
setInstructorName(instrctor);
}

void GradeBook::setCourseName(string name)
{
courseName = name;
}


void GradeBook::setInstructorName(string instructor)
{
instructorName = instructor;
}


string GradeBook::getCourseName()
{
return courseName;
}


string GradeBook::getInstructorName()
{
return instructorName;
}


void GradeBook::displayMessage()
{

cout << "Welcome to the grade book for\n" << getCourseName()
<< "\nThis course is presented by: "<< getInstructorName()
<< "!" << endl;
}
32 changes: 32 additions & 0 deletions Mehdi/Assignments 1/CH3/CH3-12-main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#include <iostream>
#include "Account.h"
using namespace std;

// function main begins program execution
int main()
{

Account customer1(20);
Account customer2(30);




cout << "\nAn account created for customer1. Its balace is : $" << customer1.getBalance();
customer1.debit(10);
cout <<"\nWithdraw $10. Balance : $" << customer1.getBalance();
customer1.credit(33);
cout << "\nDeposit $33. Balance : $" << customer1.getBalance();
cout << "\nWithdraw $90. Balance : ";
customer1.debit(90);

cout << "\nAn account created for customer2. Its balace is : $" << customer2.getBalance();
customer2.debit(10);
cout << "\nWithdraw $10. Balance : $" << customer2.getBalance();
customer2.credit(33);
cout << "\nDeposit $33. Balance : $" << customer2.getBalance();
cout << "\nWithdraw $90. Balance : ";
customer2.debit(90);

} // end main
36 changes: 36 additions & 0 deletions Mehdi/Assignments 1/CH3/CH3-12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include "Account.h" // include definition of class Account
using namespace std;


Account::Account(int balance)
{
if (balance > 0)
account_balance = balance;
else {
cout << "\nInitial balance was invalid\n";
account_balance = 0;
}

}


void Account::credit(int credit)
{
account_balance += credit;
}


void Account::debit(int withdraw)
{
if (withdraw < account_balance)
account_balance -= withdraw;
else
cout << "\nDebit amount exceeded account balance.\n";
}


int Account::getBalance()
{
return account_balance;
}
56 changes: 56 additions & 0 deletions Mehdi/Assignments 1/CH3/CH3-13-main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#include <iostream>
#include "Invoice.h"
using namespace std;


int main()
{

Invoice product1("MC302", "Laptop", 3, 1050);
Invoice product2("MMX83", "Iphone", 1, 520);




cout << "\nInformation of Product 1:";
cout << "\nPart number: " << product1.get_part_number();
cout << "\nPart description: " << product1.get_part_description();
cout << "\nQuantity: " << product1.get_quantity();
cout << "\nPrice: " << product1.get_price();
cout << "\nInvoice: " << product1.get_invoice();

product1.set_part_number("MC702");
product1.set_part_description("PC");
product1.set_quantity(6);
product1.set_price(1220);

cout << "\n\nInformation of Product 1 Updated:";
cout << "\nPart number: " << product1.get_part_number();
cout << "\nPart description: " << product1.get_part_description();
cout << "\nQuantity: " << product1.get_quantity();
cout << "\nPrice: " << product1.get_price();
cout << "\nInvoice: " << product1.get_invoice();


cout << "\n\nInformation of Product 2:";
cout << "\nPart number: " << product2.get_part_number();
cout << "\nPart description: " << product2.get_part_description();
cout << "\nQuantity: " << product2.get_quantity();
cout << "\nPrice: " << product2.get_price();
cout << "\nInvoice: " << product2.get_invoice();

product2.set_part_number("MXX708");
product2.set_part_description("iPhone");
product2.set_quantity(7);
product2.set_price(880);


cout << "\n\nInformation of Product 2 Updated:";
cout << "\nPart number: " << product2.get_part_number();
cout << "\nPart description: " << product2.get_part_description();
cout << "\nQuantity: " << product2.get_quantity();
cout << "\nPrice: " << product2.get_price();
cout << "\nInvoice: " << product2.get_invoice() << endl << endl;

} // end main
Loading