- // Wyatt Vandenburg
- // Paintingco.cpp
- // the following code takes in the the size of a painting job and calculates the size of job, how many paint cans it
- // will take and the cost, next the program takes an inputed numeric date and calculates the day of the week, and
- // the calculates the correct month while considering if there is a leap year or not
- // Xcode
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- void displayTitle();
- void getData(int &length, int &width);
- char convert12Format(int &hour);
- int calcSqMeter(int length, int width);
- int calcTotalCans(int area);
- double calcCost(int cans);
- void displayResults(int area, int cans, double cost);
- bool isLeapYear(int year);
- int getYearValue(int year);
- int getMonthNumber(string month);
- int getMonthVa0lue(int m, int year);
- int dayOfWeek(int day, int month, int year);
- void displayMsg(int cans);
- int main()
- {
- int length, width, hour, minute, day, month, year;
- string weekDay[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- string monthsInYear[] = {"January", "Feburary", "March","April", "May", "June", "July", "August", "September", "November", "Decemeber"};
- //
- displayTitle();
- getData(length, width);
- while (length != 0) {
- cout << " Enter the transaction time in 24-hour notation: " <<endl;
- cout<<" Hour: ";
- cin >> hour;
- cout<<" Minute: ";
- cin >> minute;
- cout << " Enter the transaction date (dd mm yyyy): ";
- cin >> day >> month >> year;
- int area = calcSqMeter(length, width);
- int cans = calcTotalCans(area);
- double cost = calcCost(cans);
- displayResults(area, cans, cost);
- int idx = dayOfWeek(day, month, year);
- char ampm = convert12Format(hour);
- cout << "\n\tDate/Time: " << weekDay[idx] <<", " << monthsInYear[month -1] << " " << day << ", " << year
- << " " << hour << ":" << minute;
- if(ampm == 'P')
- cout<<"PM" << endl;
- else
- cout <<"AM"<<endl;
- displayMsg(cans);
- cout <<"\tThank you for your purchase.\n "<<endl;
- cout <<"========================================================="<<endl;
- getData(length, width);
- }
- }
- void displayTitle()
- {
- cout<<"\t\tRainbow Printing Company Paint Costing"<<endl;
- cout<<"\t-----------------------------------------------"<<endl;
- }
- // uses call by reference
- void getData(int &length, int &width)
- {
- cout<<"\n Enter the length in meter (0 to stop).....";
- cin >> length;
- if(length == 0)
- return;
- cout<<" Enter the width in meter....................";
- cin >> width;
- }
- // this method converts 24 hour period into a 12 hour also is using call by reference
- char convert12Format(int &hour)
- {
- if(hour > 12)
- {
- hour = hour - 12;
- return 'P';
- }
- return 'A';
- }
- //function receives the values for length and width, and
- int calcSqMeter(int length, int width)
- {
- int height = 3;
- return length * width + 2 * height * (length + width);
- }
- //function calculates and returns the # of cans
- int calcTotalCans(int area)
- {
- int coverArea = 20;
- int cans = ceil((double)area/coverArea); // ceil will round the value up
- return cans;
- }
- //function calculates and returns the total cost
- double calcCost(int cans)
- {
- double price = 15.50;
- return cans * price;
- }
- // method displays numeric values and makes sure that the cost is set to two decimal places
- void displayResults(int area, int cans, double cost)
- {
- cout << "\n--------------------------------------------------------------------------"<<endl;
- cout << "\tArea\t\t=\t\t" << area << " Square meters"<<endl;
- cout << "\tCans\t\t=\t\t" << cans << endl;
- cout<<fixed <<setprecision(2);
- cout << "\tCost\t\t=\t\t" << cost << endl;
- }
- // the year must be divisble by 400 OR be divisible by 4 AND is NOT divisible by 100
- bool isLeapYear(int year)
- {
- if(!(year%4 && year%100)||year%400)
- return false; // if the above conditiion is met it is true otherwise the statement is false, and the year is not a leap year.
- else
- return true;
- }
- //function computes a value based on the years since the beginning of the century
- int getYearValue(int year)
- {
- int remainder;
- remainder = year%100;
- int num;
- num= remainder / 4;
- return remainder + num;
- }
- //function returns a month number based on a 3 charater month name
- int getMonthNumber(int m)
- {
- switch(m)
- {
- case 1:
- cout << ("January\n");
- break;
- case 2:
- cout << ("February\n");
- break;
- case 3:
- cout << ("March\n");
- break;
- case 4:
- cout << ("April\n");
- break;
- case 5:
- cout << ("May\n");
- break;
- case 6:
- cout << ("June\n");
- break;
- case 7:
- cout << ("July\n");
- break;
- case 8:
- cout << ("August\n");
- break;
- case 9:
- cout << ("September\n");
- break;
- case 10:
- cout << ("October\n");
- break;
- case 11:
- cout << ("November\n");
- break;
- case 12:
- cout << ("December\n");
- break;
- default:
- cout << ("invalid Month number. \nPlease try again ....\n");
- break;
- }return m;}
- //function uses the values in the textbook and envokes the isLeapYear function
- int getMonthVa0lue(int month, int year)
- {
- const int modifier[] = {
- 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5
- };
- if (month > 12 || month < 1)
- return -1;
- else if (month > 2 || !isLeapYear(year))
- return modifier[month - 1];
- else
- return (modifier[month - 1] + 6) % 7;
- }
- //function returns the day of the week of the specified date as an int (Sunday = 0, Monday = 1, etc.)
- int dayOfWeek(int d, int m, int y)
- {
- static int t[] = { 0, 3, 2, 5, 0, 3,
- 5, 1, 4, 6, 2, 4 };
- y -= m < 3;
- return ( y + y / 4 - y / 100 +
- y / 400 + t[m - 1] + d) % 7;
- }
- // this fucntion will give the customer a free gift depending on the amount of cans they purchcase
- void displayMsg(int cans)
- {
- if(cans>1 && cans<4)
- cout<<"Gift: free paint brush\n "<<endl;
- else if(cans < 8)
- cout<<"Gift: Free paint tray\n"<<endl;
- else
- cout<<"Gift: $10 gift card\n"<<endl;
- }