Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //3.9 main file
- #include <iostream>
- #include "account.h";
- using namespace std;
- int main()
- {
- Account test1("Jones", 400);
- cout << "Current balance is.... " << test1.getBalance() << endl;
- cout << test1.withdraw(500) << endl;
- cout << test1.getBalance();
- return 0;
- }
- //3.9 account.h file
- #include <string>
- #include <iostream>
- class Account {
- public:
- Account(std::string accountName, int initialBalance)
- : name{accountName} {
- if (initialBalance > 0) {
- balance = initialBalance;
- }
- }
- void deposit(int depositAmount) {
- if (depositAmount > 0) {
- balance = balance + depositAmount;
- }
- }
- int getBalance() const {
- return balance;
- }
- void setName(std::string accountName) {
- name = accountName;
- }
- std::string getName() const {
- return name;
- }
- std::string withdraw(int withdrawAmount) {
- if (withdrawAmount > balance) {
- return("You do not have enough money in your account to do that.");
- }
- else {
- balance = balance - withdrawAmount;
- return("Money withdrawn succesfully.");
- }
- }
- private:
- std::string name;
- int balance{0};
- };
- //3.10 main file
- #include <iostream>
- #include "invoice.h";
- using namespace std;
- void test();
- int main()
- {
- test();
- return 0;
- }
- void test() {
- Invoice test1("1234","ChainsawOil",2,4);
- cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
- test1.setDescript("Chain");
- test1.setPartNum("4321");
- test1.setPrice(3);
- test1.setQuantity(8);
- cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
- cout << "Total invoice amount: $" << test1.getInvoiceAmount() << endl;
- test1.setPrice(-3);
- test1.setQuantity(-8);
- cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
- }
- //3.10 header file
- #include <string>
- #include <iostream>
- class Invoice {
- public:
- Invoice(std::string initNum, std::string initDescript, int initPrice, int initQuantity)
- : partNum{initNum}, partDescription{initDescript} {
- if ( initPrice < 0) {
- partPrice = 0;
- }
- else {
- partPrice = initPrice;
- }
- if ( initQuantity < 0) {
- partQuantity = 0;
- }
- else {
- partQuantity = initQuantity;
- }
- }
- std::string getPartNum() const {
- return(partNum);
- }
- void setPartNum(std::string newPartNum) {
- partNum = newPartNum;
- }
- std::string getDescript() const {
- return(partDescription);
- }
- void setDescript(std::string newDescript) {
- partDescription = newDescript;
- }
- int getPrice() const {
- return(partPrice);
- }
- void setPrice(int newPrice) {
- if ( newPrice < 0) {
- partPrice = 0;
- }
- else {
- partPrice = newPrice;
- }
- }
- int getQuantity() const {
- return(partQuantity);
- }
- void setQuantity(int newQuantity) {
- if ( newQuantity < 0) {
- partQuantity = 0;
- }
- else {
- partQuantity = newQuantity;
- }
- }
- int getInvoiceAmount() {
- return (partPrice * partQuantity);
- }
- private:
- std::string partNum;
- std::string partDescription;
- int partPrice;
- int partQuantity;
- };
- //3.12 main
- #include <iostream>
- #include "date.h"
- using namespace std;
- void test();
- int main()
- {
- test();
- return 0;
- }
- void test() {
- Date test2(11,24,1991);
- test2.displayDate();
- test2.setDay(22);
- test2.setMonth(22);
- test2.setYear(2002);
- test2.displayDate();
- }
- //3.12 header
- #include <iostream>
- #include <string>
- class Date {
- public:
- Date (int initMonth, int initDay, int initYear)
- : month{initMonth}, day{initDay}, year{initYear} {}
- int getMonth() {
- return month;
- }
- int getDay() {
- return day;
- }
- int getYear() {
- return year;
- }
- void setMonth(int newMonth) {
- if ( newMonth > 12 || newMonth < 1) {
- month = 1;
- }
- else {
- month = newMonth;
- }
- }
- void setDay(int newDay) {
- day = newDay;
- }
- void setYear(int newYear) {
- year = newYear;
- }
- void displayDate() {
- std::cout << month << "/" << day << "/" << year << std::endl;
- }
- private:
- int month;
- int day;
- int year;
- };
Add Comment
Please, Sign In to add comment