Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////// A 3 - INVOICE Class //////////////////
- // PG1Lab2 - Exercise 3
- // Invoice.h
- // Author: Alexander Schott
- // Date: 21.04.2014
- #include <iostream>
- #include <string>
- class Invoice{
- public:
- Invoice(std::string, std::string, int, double);
- void setPartNumber(std::string);
- std::string getPartNumber() const;
- void setPartDescription(std::string);
- std::string getPartDescription() const;
- void setQuantity(int);
- int getQuantity() const;
- void setPricePerItem(double);
- double getPricePerItem() const;
- double computeInvoiceAmount();
- private:
- std::string partNumber;
- std::string partDescription;
- int quantity;
- double pricePerItem;
- };
- // PG1Lab2 - Exercise 3
- // Invoice.cpp
- // Author: Alexander Schott
- // Date: 21.04.2014
- #include "Invoice.h"
- using namespace std;
- // constructor
- Invoice::Invoice(string number, string description, int size, double price)
- : partNumber(number), partDescription(description), quantity(size), pricePerItem(price){
- }
- void Invoice::setPartNumber(string number){
- partNumber = number;
- }
- string Invoice::getPartNumber() const{
- return partNumber;
- }
- void Invoice::setPartDescription(string description){
- partDescription = description;
- }
- string Invoice::getPartDescription() const{
- return partDescription;
- }
- void Invoice::setQuantity(int size){
- if (size < 0) quantity = 0;
- else quantity = size;
- }
- int Invoice::getQuantity() const{
- return quantity;
- }
- void Invoice::setPricePerItem(double price){
- if (price < 0.0) pricePerItem = 0.0;
- else pricePerItem = price;
- }
- double Invoice::getPricePerItem() const{
- return pricePerItem;
- }
- double Invoice::computeInvoiceAmount(){
- return quantity*pricePerItem;
- }
- // PG1Lab2 - Exercise 3
- // main.cpp
- // Author: Alexander Schott
- // Date: 20.04.2014
- #include "Invoice.h"
- using namespace std;
- int main(){
- Invoice Hammer("123.h3", "Hammer Typ 3", 23, 12.95);
- // Hammer.setPricePerItem(-3.3); // test negative pricePerItem
- // Hammer.setQuantity(-11); // test negative quantity
- cout << "----------------------- Invoice " <<
- "-----------------------" << endl;
- cout << "Part #:\tDescription:\tQuantity:\tPrice per Item:\n"
- << Hammer.getPartNumber() << "\t" << Hammer.getPartDescription() << "\t"
- << Hammer.getQuantity() << "\t\t" << Hammer.getPricePerItem() << "\n------"
- << "-------------------------------------------------" << endl;
- cout << "Total: " << Hammer.computeInvoiceAmount() << endl;
- return 0;
- }
- //////////////// A 4 - DATE Class //////////////////
- // PG1Lab2 - Exercise 4
- // Date.h
- // Author: Alexander Schott
- // Date: 21.04.2014
- #include <string>
- class Date{
- public:
- Date(int, int, int);
- void setDay(int);
- int getDay() const;
- void setMonth(int);
- int getMonth() const;
- void setYear(int);
- int getYear() const;
- std::string toString() const;
- private:
- int day;
- int month;
- int year;
- };
- // PG1Lab2 - Exercise 4
- // Date.cpp
- // Author: Alexander Schott
- // Date: 21.04.2014
- #include <iostream>
- #include "Date.h"
- using namespace std;
- Date::Date(int d, int m , int y){
- setDay(d);
- setMonth(m);
- setYear(y);
- }
- void Date::setDay(int d){
- day = d;
- }
- int Date::getDay() const{
- return day;
- }
- void Date::setMonth(int m){
- if (m < 1 || m > 12) {
- cout << "month value not accepted! 1 <= month <= 12!" << endl <<
- "month is set to 1" << endl;
- month = 1;
- }
- else month = m;
- }
- int Date::getMonth() const{
- return month;
- }
- void Date::setYear(int y){
- year = y;
- }
- int Date::getYear() const{
- return year;
- }
- string Date::toString() const{
- return to_string(getDay()) + "." + to_string(getMonth()) + "." + to_string(getYear());
- }
- // PG1Lab2 - Exercise 4
- // main.cpp
- // Author: Alexander Schott
- // Date: 21.04.2014
- #include <iostream>
- #include "Date.h"
- using namespace std;
- int main(){
- int d = 0, m = 0, y = 0;
- Date TestDate(1, 1, 2000);
- cout << "TestDate: " + TestDate.toString() << endl;
- cout << "Input a Testdate (day,month,year): ";
- cin >> d >> m >> y;
- TestDate.setDay(d);
- TestDate.setMonth(m);
- TestDate.setYear(y);
- cout << "TestDate: " + TestDate.toString() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement