From bee3bdaac47530fc0b4f7a9a461aabe21c61a564 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:47:27 +0800 Subject: [PATCH 01/19] Create Acount,h --- 201816040216/Lab1/Acount,h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 201816040216/Lab1/Acount,h diff --git a/201816040216/Lab1/Acount,h b/201816040216/Lab1/Acount,h new file mode 100644 index 0000000..a4279a3 --- /dev/null +++ b/201816040216/Lab1/Acount,h @@ -0,0 +1,14 @@ +// Lab 1: Account.h +// Definition of Account class. + +class Account +{ +public: + Account( int ); // constructor initializes balance + void Debit( int ); // add an amount to the account balance + /* write code to declare member function debit. */ + int getBalance(); // return the account balance +private: + int balance; // data member that stores the balance +}; // end class Account + From baf72e18707447025af0d82ab007a81c36b1f60b Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:48:06 +0800 Subject: [PATCH 02/19] Create Acount.cpp --- 201816040216/Lab1/Acount.cpp | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 201816040216/Lab1/Acount.cpp diff --git a/201816040216/Lab1/Acount.cpp b/201816040216/Lab1/Acount.cpp new file mode 100644 index 0000000..2cd5f8d --- /dev/null +++ b/201816040216/Lab1/Acount.cpp @@ -0,0 +1,41 @@ +// Lab 1: Account.cpp +// Member-function definitions for class Account. +#include +using namespace std; + +#include "Account.h" // include definition of class Account + +// Account constructor initializes data member balance +Account::Account( int initialBalance ) +{ + balance = 0; // assume that the balance begins at 0 + + // if initialBalance is greater than 0, set this value as the + // balance of the Account; otherwise, balance remains 0 + if ( initialBalance > 0 ) + balance = initialBalance; + + // if initialBalance is negative, print error message + if ( initialBalance < 0 ) + cout << "Error: Initial balance cannot be negative.\n" << endl; +} // end Account constructor + +// credit (add) an amount to the account balance +void Account::Debit( int amount ) +{ + balance = balance - amount; // add amount to balance + if(balance<0) + { + cout<<"Debit amout exceeded account balance."<<"\n"; + balance=0; + } +} // end function credit + +/* write code to define member function debit. */ + + +// return the account balance +int Account::getBalance() +{ + return balance; // gives the value of balance to the calling function +} // end function getBalance From 6d3bd5fcd9c990ecf969da27c5a62cefcf7dd19e Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:48:33 +0800 Subject: [PATCH 03/19] Create AcountText,cpp --- 201816040216/Lab1/AcountText,cpp | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 201816040216/Lab1/AcountText,cpp diff --git a/201816040216/Lab1/AcountText,cpp b/201816040216/Lab1/AcountText,cpp new file mode 100644 index 0000000..723f92a --- /dev/null +++ b/201816040216/Lab1/AcountText,cpp @@ -0,0 +1,40 @@ +// Lab 1: AccountTest.cpp +// Create and manipulate Account objects. +#include +using namespace std; + +// include definition of class Account from Account.h +#include "Account.h" + +// function main begins program execution +int main() +{ + Account account1( 50 ); // create Account object + Account account2( 0 ); // create Account object + + // display initial balance of each object + cout << "account1 balance: $" << account1.getBalance() << endl; + cout << "account2 balance: $" << account2.getBalance() << endl; + + int withdrawalAmount; // stores withdrawal amount read from user + + cout << "\nEnter withdrawal amount for account1: "; // prompt + cin >> withdrawalAmount; // obtain user input + cout << "\nsubtracting " << withdrawalAmount + << " from account1 balance\n\n"; + /* write code to withdraw money from account1 */ + account1.Debit(withdrawalAmount); + // display balances + cout << "account1 balance: $" << account1.getBalance() << endl; + cout << "account2 balance: $" << account2.getBalance() << endl; + + cout << "\nEnter withdrawal amount for account2: "; // prompt + cin >> withdrawalAmount; // obtain user input + cout << "\nsubtracting " << withdrawalAmount + << " from account2 balance\n\n"; + /* write code to withdraw money from account2 */ + account2.Debit(withdrawalAmount); + // display balances + cout << "account1 balance: $" << account1.getBalance() << endl; + cout << "account2 balance: $" << account2.getBalance() << endl; +} // end main From 2ddb454eb2fccc20b9b5e4366c668cd98a211106 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:49:29 +0800 Subject: [PATCH 04/19] Create GradeBook.h --- 201816040216/Lab2/GradeBook.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 201816040216/Lab2/GradeBook.h diff --git a/201816040216/Lab2/GradeBook.h b/201816040216/Lab2/GradeBook.h new file mode 100644 index 0000000..056832f --- /dev/null +++ b/201816040216/Lab2/GradeBook.h @@ -0,0 +1,28 @@ +// Lab 2: GradeBook.h +// Definition of GradeBook class that stores an instructor's name. +#include // program uses C++ standard string class +using namespace std; + +// GradeBook class definition +class GradeBook +{ +public: + // constructor initializes course name and instructor name + GradeBook( string, string ,string); + void setCourseName( string ); // function to set the course name + string getCourseName(); // function to retrieve the course name + + /* write code to declare a get function for the instructor's name */ + void setInstructorName( string ); + /* write code to declare a set function for the instructor's name */ + string getCourseInstructor(); + + void setInstructorMing(string); + string getInstructorMing(); + + void displayMessage(); // display welcome message and instructor name +private: + string courseName; // course name for this GradeBook + string instructorName; // instructor name for this GradeBook + string instructorMing;//instructor Ming for this Gradebook +}; // end class GradeBook From 24a0860b20b95812886362f9b33ab371ea131150 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:49:54 +0800 Subject: [PATCH 05/19] Create GradeBook.cpp --- 201816040216/Lab2/GradeBook.cpp | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 201816040216/Lab2/GradeBook.cpp diff --git a/201816040216/Lab2/GradeBook.cpp b/201816040216/Lab2/GradeBook.cpp new file mode 100644 index 0000000..2393614 --- /dev/null +++ b/201816040216/Lab2/GradeBook.cpp @@ -0,0 +1,57 @@ +// Lab 2: GradeBook.cpp +// Member-function definitions for class GradeBook. +#include +using namespace std; + +// include definition of class GradeBook from GradeBook.h +#include "GradeBook.h" + +// constructor initializes courseName and instructorName +// with strings supplied as arguments +GradeBook::GradeBook( string course, string instructor,string Ming ) +{ + setCourseName( course ); // initializes courseName + setInstructorName( instructor ); // initialiZes instructorName + setInstructorMing(Ming); +} // end GradeBook constructor + +// function to set the course name +void GradeBook::setCourseName( string name ) +{ + courseName = name; // store the course name +} // end function setCourseName + +// function to retrieve the course name +string GradeBook::getCourseName() +{ + return courseName; +} // end function getCourseName + +/* write code to define a get member function for the instructor's name */ +void GradeBook::setInstructorName( string instructor ) +{ + instructorName=instructor;// store the course instruct +}// end function setCourseInstructor +/* write code to define a set member function for the instructor's name */ +string GradeBook::getCourseInstructor() +{ + return instructorName; +}// end function getCourseInstructtor +// display a welcome message and the instructor's name +void GradeBook::setInstructorMing(string ming ) +{ + instructorMing=ming; +}// end function setInstructorMing + +string GradeBook::getInstructorMing() +{ + return instructorMing; +}// end function getCourseInstructorMing +void GradeBook::displayMessage() +{ + // display a welcome message containing the course name + cout << "Welcome to the grade book for\n" << getCourseName() << "!" + << endl; + /* write code to output the instructor's name */ + cout<<"This course is presented by:"< Date: Thu, 21 Nov 2019 17:50:21 +0800 Subject: [PATCH 06/19] Create GradeBookText.cpp --- 201816040216/Lab2/GradeBookText.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 201816040216/Lab2/GradeBookText.cpp diff --git a/201816040216/Lab2/GradeBookText.cpp b/201816040216/Lab2/GradeBookText.cpp new file mode 100644 index 0000000..7463e8a --- /dev/null +++ b/201816040216/Lab2/GradeBookText.cpp @@ -0,0 +1,29 @@ +// Lab 2: GradeBookTest.cpp +// Test program for modified GradeBook class. +#include +using namespace std; + +// include definition of class GradeBook from GradeBook.h +#include "GradeBook.h" + +// function main begins program execution +int main() +{ + // create a GradeBook object; pass a course name and instructor name + string courseinstructor,InstructorMing; + GradeBook gradeBook( + "CS101 Introduction to C++ Programming","Sam","Smith" ); + // display welcome message and instructor's name + gradeBook.displayMessage(); + cout<<"\n"; + /* write code to change instructor's name and output changes */ + cout<<"Changing instrutor name to"; + cin>>courseinstructor; + cin>>InstructorMing; + + gradeBook.setInstructorName(courseinstructor); + gradeBook.setInstructorMing(InstructorMing); + gradeBook.displayMessage(); + + +} // end main From e1be971478cbcc3c4ff42145d498346dcc5d4c08 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:50:58 +0800 Subject: [PATCH 07/19] Create Employee.h --- 201816040216/Lab3/Employee.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 201816040216/Lab3/Employee.h diff --git a/201816040216/Lab3/Employee.h b/201816040216/Lab3/Employee.h new file mode 100644 index 0000000..a5f2dc2 --- /dev/null +++ b/201816040216/Lab3/Employee.h @@ -0,0 +1,35 @@ +// Lab 3: Employee.h +// Employee class definition. + +#include // program uses C++ standard string class +using namespace std; + +// Employee class definition +class Employee +{ +public: + /* Declare a constructor that has one parameter for each data member */ + Employee(string,string,int); + /* Declare a set method for the employee's first name */ + void setEmployeename(string); + /* Declare a get method for the employee's first name */ + string getEmployeename(); + /* Declare a set method for the employee's last name */ + void setEmployeeming(string); + /* Declare a get method for the employee's last name */ + string getEmployeeming(); + /* Declare a set method for the employee's monthly salary */ + void setEmployeemoney(int); + /* Declare a get method for the employee's monthly salary */ + int getEmployeemoney(); + void displaymessage();// display welcome message and instructor name + void displaymessage1(); + int increasingmoney(int); +private: + /* Declare a string data member for the employee's first name */ + string Employeename; + /* Declare a string data member for the employee's last name */ + string Employeeming; + /* Declare an int data member for the employee's monthly salary */ + int Employeemoney,Employeemoney1; +}; // end class Employee From 5a2b288e3ecb35606e7a05b6475769617165b83f Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:51:29 +0800 Subject: [PATCH 08/19] Create Employee.cpp --- 201816040216/Lab3/Employee.cpp | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 201816040216/Lab3/Employee.cpp diff --git a/201816040216/Lab3/Employee.cpp b/201816040216/Lab3/Employee.cpp new file mode 100644 index 0000000..a9c116b --- /dev/null +++ b/201816040216/Lab3/Employee.cpp @@ -0,0 +1,64 @@ +// Lab 3: Employee.cpp +// Employee class member-function definitions. +#include +using namespace std; + +#include "Employee.h" // Employee class definition +Employee::Employee(string name,string ming,int money) +{ + setEmployeename(name); + setEmployeeming(ming); + setEmployeemoney(money); +} +/* Define the constructor. Assign each parameter value to the appropriate data + member. Write code that validates the value of salary to ensure that it is + not negative. */ + +/* Define a set function for the first name data member. */ +void Employee::setEmployeename(string name) +{ + Employeename=name;// store the Employee name +}//end function setEmployeename +/* Define a get function for the first name data member. */ +string Employee::getEmployeename() +{ + return Employeename; +}//end function getEmployeename +/* Define a set function for the last name data member. */ +void Employee::setEmployeeming(string ming) +{ + Employeeming=ming;// store the Employee ming +/* Define a get function for the last name data member. */ + +} +string Employee::getEmployeeming() +{ + return Employeeming; +}//end function getEmployeeming +/* Define a set function for the monthly salary data member. Write code + that validates the salary to ensure that it is not negative. */ +void Employee::setEmployeemoney(int money) +{ + Employeemoney=money;// store the Employee money +}//end function setEmployeemoney +/* Define a get function for the monthly salary data member. */ +int Employee::getEmployeemoney() +{ + return Employeemoney; +}//end function getEmployeemoney +void Employee::displaymessage() +{ + cout< Date: Thu, 21 Nov 2019 17:51:56 +0800 Subject: [PATCH 09/19] Create EmployeeText.cpp --- 201816040216/Lab3/EmployeeText.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 201816040216/Lab3/EmployeeText.cpp diff --git a/201816040216/Lab3/EmployeeText.cpp b/201816040216/Lab3/EmployeeText.cpp new file mode 100644 index 0000000..24c6779 --- /dev/null +++ b/201816040216/Lab3/EmployeeText.cpp @@ -0,0 +1,35 @@ +// Lab 3: EmployeeTest.cpp +// Create and manipulate two Employee objects. +#include +using namespace std; + +#include "Employee.h" // include definition of class Employee + +// function main begins program execution +int main() +{ + int a=34500,b=37800;//set employee's yearly money + + Employee employee1("Bob","Jone",a); + Employee employee2("Susan","Baker",b); + /* Create two Employee objects and assign them to Employee variables. */ + cout<<"Employee1: "; + employee1.displaymessage(); + /* Output the first name, last name and salary for each Employee. */ + cout<<"Employee2: "; + employee2.displaymessage(); + /* Give each Employee a 10% raise. */ + cout< Date: Thu, 21 Nov 2019 17:52:27 +0800 Subject: [PATCH 10/19] Create Complex.h --- 201816040216/Lab4/Complex.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 201816040216/Lab4/Complex.h diff --git a/201816040216/Lab4/Complex.h b/201816040216/Lab4/Complex.h new file mode 100644 index 0000000..6335154 --- /dev/null +++ b/201816040216/Lab4/Complex.h @@ -0,0 +1,20 @@ +// Lab 4: Complex.h +#ifndef COMPLEX_H +#define COMPLEX_H + +/* Write class definition for Complex */ +class Complex +{ + public: + Complex(double,double); + void printComplex(); + Complex subtract(const Complex &); + Complex add(const Complex &); + void setComplexNumber(double,double); + + private: + double realPart; + double imaginaryPart; +}; +#endif + From f9c374c5d89370a9a7914528f831d14c823d5983 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:52:49 +0800 Subject: [PATCH 11/19] Create Complex.cpp --- 201816040216/Lab4/Complex.cpp | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 201816040216/Lab4/Complex.cpp diff --git a/201816040216/Lab4/Complex.cpp b/201816040216/Lab4/Complex.cpp new file mode 100644 index 0000000..6e4a868 --- /dev/null +++ b/201816040216/Lab4/Complex.cpp @@ -0,0 +1,45 @@ +// Lab 4: Complex.cpp +// Member-function definitions for class Complex. +#include +using namespace std; + +#include "Complex.h" + +Complex::Complex( double real, double imaginary ) +{ + setComplexNumber( real, imaginary ); +} // end Complex constructor + +Complex Complex::add( const Complex &right ) +{ + /* Write a statement to return a Complex object. Add + the realPart of right to the realPart of this Complex + object and add the imaginaryPart of right to the + imaginaryPart of this Complex object */ + Complex t(0,0); + t.setComplexNumber( right.realPart + realPart, right.imaginaryPart + imaginaryPart); + return t; + +} // end function add + +Complex Complex::subtract( const Complex &right ) +{ + /* Write a statement to return a Complex object. Subtract + the realPart of right from the realPart of this Complex + object and subtract the imaginaryPart of right from + the imaginaryPart of this Complex object */ + Complex temp(0,0); + temp.setComplexNumber( realPart - right.realPart,imaginaryPart - right.imaginaryPart); + return temp; +} // end function subtract + +void Complex::printComplex() +{ + cout << '(' << realPart << ", " << imaginaryPart << ')'; +} // end function printComplex + +void Complex::setComplexNumber( double rp, double ip ) +{ + realPart = rp; + imaginaryPart = ip; +} // end function setComplexNumber From 69e7010df9f970449146036c4c7f45f77661d005 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:54:06 +0800 Subject: [PATCH 12/19] Create ComplexText.cpp --- 201816040216/Lab4/ComplexText.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 201816040216/Lab4/ComplexText.cpp diff --git a/201816040216/Lab4/ComplexText.cpp b/201816040216/Lab4/ComplexText.cpp new file mode 100644 index 0000000..f8f891d --- /dev/null +++ b/201816040216/Lab4/ComplexText.cpp @@ -0,0 +1,30 @@ +// Lab 4: ComplexTest.cpp +#include +using namespace std; + +#include "Complex.h" + +int main() +{ + Complex a( 1, 7 ), b( 9, 2 ), c(0,0); // create three Complex objects + + a.printComplex(); // output object a + cout << " + "; + b.printComplex(); // output object b + cout << " = "; + c = a.add( b ); // invoke add function and assign to object c + c.printComplex(); // output object c + + cout << '\n'; + a.setComplexNumber( 10, 1 ); // reset realPart and + b.setComplexNumber( 11, 5 ); // and imaginaryPart + a.printComplex(); // output object a + cout << " - "; + b.printComplex(); // output object b + cout << " = "; + c = a.subtract( b ); // invoke add function and assign to object c + c.printComplex(); // output object c + cout << endl; +} // end main + + From b1e377ef6ae520fbd4c15ab3e698fe04d2ba00cc Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:54:36 +0800 Subject: [PATCH 13/19] Create Date.h --- 201816040216/Lab5/Date.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 201816040216/Lab5/Date.h diff --git a/201816040216/Lab5/Date.h b/201816040216/Lab5/Date.h new file mode 100644 index 0000000..770580c --- /dev/null +++ b/201816040216/Lab5/Date.h @@ -0,0 +1,29 @@ +// Lab 5: Date.h +#ifndef DATE_H +#define DATE_H + +class Date +{ +public: + Date( int = 1, int = 1, int = 2000 ); // default constructor + void print(); // print function + void setDate( int, int, int ); // set month, day, year + void setMonth( int ); // set month + void setDay( int ); // set day + void setYear( int ); // set year + int getMonth(); // get month + int getDay(); // get day + int getYear(); // get year + /* Write a member function prototype for nextDay, + which will increment the Date by one day */ + void nextday (int ,int ,int ); + +private: + int month; // 1-12 + int day; // 1-31 (except February(leap year), April, June, Sept, Nov) + int year; // 1900+ + bool leapYear(); // leap year + int monthDays(); // days in month +}; // end class Date + +#endif From cccc3dadb706b3199e260b73f992c6951b57d5fa Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:54:52 +0800 Subject: [PATCH 14/19] Create Date.cpp --- 201816040216/Lab5/Date.cpp | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 201816040216/Lab5/Date.cpp diff --git a/201816040216/Lab5/Date.cpp b/201816040216/Lab5/Date.cpp new file mode 100644 index 0000000..984f72f --- /dev/null +++ b/201816040216/Lab5/Date.cpp @@ -0,0 +1,98 @@ +// Lab 5: Date.cpp +// Member-function definitions for class Date. +#include +using namespace std; + +#include "Date.h" // include definition of class Date + +Date::Date( int m, int d, int y ) +{ + setDate( m, d, y ); // sets date +} // end Date constructor + +void Date::setDate( int mo, int dy, int yr ) +{ + setMonth( mo ); // invokes function setMonth + setDay( dy ); // invokes function setDay + setYear( yr ); // invokes function setYear +} // end function setDate + +void Date::setDay( int d ) +{ + if ( month == 2 && leapYear() ) + day = ( d <= 29 && d >= 1 ) ? d : 1; + else + day = ( d <= monthDays() && d >= 1 ) ? d : 1; +} // end function setDay + +void Date::setMonth( int m ) +{ + month = m <= 12 && m >= 1 ? m : 1; // sets month +} // end function setMonth + +void Date::setYear( int y ) +{ + year = y >= 1900 ? y : 1900; // sets year +} // end function setYear + +int Date::getDay() +{ + return day; +} // end function getDay + +int Date::getMonth() +{ + return month; +} // end function getMonth + +int Date::getYear() +{ + return year; +} // end function getYear + +void Date::print() +{ + cout << month << '-' << day << '-' << year << '\n'; // outputs date +} // end function print + +/* Write code to define member function nextDay; + make sure to check if the new day is the start of + a new month or a new year */ +void Date::nextday(int m,int d,int y) +{ + + if(d==31&&m==12) + { + y++; + setYear(y); + } + + d=d+1; + setDay(d); + + if(day==1) + m++; + + + setMonth(m); +}//end + + + + + +bool Date::leapYear() +{ + if ( getYear() % 400 == 0 || ( getYear() % 4 == 0 && getYear() % 100 != 0 ) ) + return true; // is a leap year + else + return false; // is not a leap year +} // end function leapYear + +int Date::monthDays() +{ + const int days[ 12 ] = + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + return getMonth() == 2 && leapYear() ? 29 : days[ getMonth() - 1 ]; +} // end function monthDays From 43dc4fa3564507d1f6a34e03edf4c24e85f32cff Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:55:44 +0800 Subject: [PATCH 15/19] Create DateText.cpp --- 201816040216/Lab5/DateText.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 201816040216/Lab5/DateText.cpp diff --git a/201816040216/Lab5/DateText.cpp b/201816040216/Lab5/DateText.cpp new file mode 100644 index 0000000..633ef47 --- /dev/null +++ b/201816040216/Lab5/DateText.cpp @@ -0,0 +1,21 @@ +// Lab 5: DateTest.cpp +#include +using namespace std; + +#include "Date.h" // include definitions of class Date + +int main() +{ + const int MAXDAYS = 16; + Date d( 12, 24, 2004 ); // instantiate object d of class Date + + // output Date object d's value + for ( int loop = 1; loop <= MAXDAYS; ++loop ) + { + d.print(); // invokes function print + /* Write call to nextDay */ + d.nextday(d.getMonth(),d.getDay(),d.getYear()); + } // end for + + cout << endl; +} // end main From a3f5ae422b0f34848329f2f86ae83d41cda7b356 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:56:51 +0800 Subject: [PATCH 16/19] Create SimpleCalculator.h --- 201816040216/Lab6/SimpleCalculator.h | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 201816040216/Lab6/SimpleCalculator.h diff --git a/201816040216/Lab6/SimpleCalculator.h b/201816040216/Lab6/SimpleCalculator.h new file mode 100644 index 0000000..597d4e1 --- /dev/null +++ b/201816040216/Lab6/SimpleCalculator.h @@ -0,0 +1,35 @@ +// Lab Exercise 6: CalcTest.cpp + +#include +using namespace std; + +#include "SimpleCalculator.h" + +int main() +{ + + double a = 10.0; + double b = 20.0; + + /* Instantiate an object of type Simplecalculator */ + cout << "The value of a is: " << a << "\n"; + cout << "The value of b is: " << b << "\n"; + + SimpleCalculator sc; + /* Write a line that adds a and b through your SimpleCalculator + object; assign the result to a variable named addition */ + double addition=sc.add(a,b); + cout << "Adding a and b yields " << addition << "\n"; + + double subtraction = sc.subtract( a, b ); + cout << "Subtracting b from a yields " << subtraction << "\n"; + + double multiplication = sc.multiply( a, b ); + cout << "Multiplying a by b yields " << multiplication << "\n"; + + /* Write a line that divides a and b through the + SimpleCalculator object; assign the result to a + variable named division */ + double division=sc.divide(a,b); + cout << "Dividing a by b yields " << division << endl; +} From ef09e50a37aa6dee9f21c101b8d88ce8ca735f8b Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:57:27 +0800 Subject: [PATCH 17/19] Create SimpleCalculator.cpp --- 201816040216/Lab6/SimpleCalculator.cpp | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 201816040216/Lab6/SimpleCalculator.cpp diff --git a/201816040216/Lab6/SimpleCalculator.cpp b/201816040216/Lab6/SimpleCalculator.cpp new file mode 100644 index 0000000..e16cfc4 --- /dev/null +++ b/201816040216/Lab6/SimpleCalculator.cpp @@ -0,0 +1,29 @@ +// Lab Exercise 6: SimpleCalculator.cpp + +#include "SimpleCalculator.h" + +/* Write definition for add member function */ +double SimpleCalculator::add( double a,double b ) const +{ + return a + b; +}//end function add + +// function subtract definition +double SimpleCalculator::subtract( double a, double b ) const +{ + return a - b; +} // end function subtract + +// function multiply definition +double SimpleCalculator::multiply( double a, double b ) const +{ + return a * b; +} // end function multiply + +/* Write definition for divide member function */ +double SimpleCalculator::divide( double a,double b )const +{ + return a / b; +}//end function divide + + From e58b101723efffa09d666b188bf2ef300f6cbaad Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:58:19 +0800 Subject: [PATCH 18/19] Update SimpleCalculator.h --- 201816040216/Lab6/SimpleCalculator.h | 42 ++++++++-------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/201816040216/Lab6/SimpleCalculator.h b/201816040216/Lab6/SimpleCalculator.h index 597d4e1..5f6dcea 100644 --- a/201816040216/Lab6/SimpleCalculator.h +++ b/201816040216/Lab6/SimpleCalculator.h @@ -1,35 +1,15 @@ -// Lab Exercise 6: CalcTest.cpp -#include -using namespace std; +// Lab Exercise 6: SimpleCalculator.h -#include "SimpleCalculator.h" - -int main() +// class SimpleCalculator definition +class SimpleCalculator { +public: + /* Write prototype for add member function */ + double add( double,double ) const; + double subtract( double, double ) const; + double multiply( double, double ) const; + /* Write prototype for divide member function */ + double divide( double,double ) const; +}; // end class SimpleCalculator - double a = 10.0; - double b = 20.0; - - /* Instantiate an object of type Simplecalculator */ - cout << "The value of a is: " << a << "\n"; - cout << "The value of b is: " << b << "\n"; - - SimpleCalculator sc; - /* Write a line that adds a and b through your SimpleCalculator - object; assign the result to a variable named addition */ - double addition=sc.add(a,b); - cout << "Adding a and b yields " << addition << "\n"; - - double subtraction = sc.subtract( a, b ); - cout << "Subtracting b from a yields " << subtraction << "\n"; - - double multiplication = sc.multiply( a, b ); - cout << "Multiplying a by b yields " << multiplication << "\n"; - - /* Write a line that divides a and b through the - SimpleCalculator object; assign the result to a - variable named division */ - double division=sc.divide(a,b); - cout << "Dividing a by b yields " << division << endl; -} From 9c6626fe7dc881f364b24056241b7b1cdcc42cf0 Mon Sep 17 00:00:00 2001 From: xinbashizi <56757060+xinbashizi@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:59:22 +0800 Subject: [PATCH 19/19] Create CalcTextr.cpp --- 201816040216/Lab6/CalcTextr.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 201816040216/Lab6/CalcTextr.cpp diff --git a/201816040216/Lab6/CalcTextr.cpp b/201816040216/Lab6/CalcTextr.cpp new file mode 100644 index 0000000..597d4e1 --- /dev/null +++ b/201816040216/Lab6/CalcTextr.cpp @@ -0,0 +1,35 @@ +// Lab Exercise 6: CalcTest.cpp + +#include +using namespace std; + +#include "SimpleCalculator.h" + +int main() +{ + + double a = 10.0; + double b = 20.0; + + /* Instantiate an object of type Simplecalculator */ + cout << "The value of a is: " << a << "\n"; + cout << "The value of b is: " << b << "\n"; + + SimpleCalculator sc; + /* Write a line that adds a and b through your SimpleCalculator + object; assign the result to a variable named addition */ + double addition=sc.add(a,b); + cout << "Adding a and b yields " << addition << "\n"; + + double subtraction = sc.subtract( a, b ); + cout << "Subtracting b from a yields " << subtraction << "\n"; + + double multiplication = sc.multiply( a, b ); + cout << "Multiplying a by b yields " << multiplication << "\n"; + + /* Write a line that divides a and b through the + SimpleCalculator object; assign the result to a + variable named division */ + double division=sc.divide(a,b); + cout << "Dividing a by b yields " << division << endl; +}