Printing Payment Program v1.1 with Delivery Service
This program optimizes some code from the original v1.0. Considering market adaptability, a delivrey service has been added. Charges range from 0.5 to 2.1 yuan based on distance from the starting point to the destination. To better serve student consumers, I will continue updating this system. Feel free to comment, like, and bookmark!
I am currently a freshman, so the code is basic. Please be kind!
Main System Header File .h
#pragma once
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
#include <cstring>
using namespace std;
#include "UserInfo.h"
void PrintMainMenu();
void PrintPrintModeMenu();
void PrintQualitySingleSideMenu();
void PrintQualityDuplexMenu();
void PrintServiceUnavailable();
void PrintExitMenu();
void PrintInvalidInput();
void PrintPremiumSingleSideMenu();
void PrintPremiumDuplexMenu();
void PrintShippingLocations();
void PrintDeliveryPrompt();
void ProcessPayment(int& count, double deliveryFee);
void ProcessDuplexPayment(int& count, double deliveryFee);
void ProcessPremiumPayment(int& count, double deliveryFee);
void ProcessPremiumDuplexPayment(int& count, double deliveryFee);
Main System .cpp
#include "MainSystem.h"
#include "UserInfo.h"
int main() {
SetConsoleTitle(TEXT("Print Charge Backend"));
system("mode con cols=80 lines=30");
backen:
PrintMainMenu();
int choice = 0;
scanf_s("%d", &choice);
while (getchar() != '\n');
switch (choice) {
case 1: {
PrintPrintModeMenu();
int subChoice = 0;
scanf_s("%d", &subChoice);
while (getchar() != '\n');
switch (subChoice) {
case 1: PrintQualitySingleSideMenu(); break;
case 2: PrintQualityDuplexMenu(); break;
case 3:
case 4:
case 7:
case 8:
PrintServiceUnavailable();
goto backen;
case 5: PrintPremiumSingleSideMenu(); break;
case 6: PrintPremiumDuplexMenu(); break;
case 9: {
PrintExitMenu();
int exitChoice = 0;
scanf_s("%d", &exitChoice);
if (exitChoice == 1) return 0;
else if (exitChoice == 2) goto backen;
else {
PrintInvalidInput();
goto backen;
}
}
default:
PrintInvalidInput();
goto backen;
}
break;
}
case 2:
cout << "Service not available yet. Please wait!" << endl;
break;
case 3: {
PrintExitMenu();
int exitChoice = 0;
scanf_s("%d", &exitChoice);
if (exitChoice == 1) return 0;
else if (exitChoice == 2) goto backen;
else {
PrintInvalidInput();
goto backen;
}
}
default:
PrintInvalidInput();
goto backen;
}
system("pause");
return 0;
}
Payment System .cpp
#include "MainSystem.h"
#include "UserInfo.h"
class PrintService {
public:
// Quality A4 printing costs
double CalculateQualitySingleSide(int sheets) {
if (sheets <= 5) return 0.38;
else if (sheets <= 15) return 0.38 + (sheets - 5) * 0.37;
else if (sheets <= 25) return 0.38 + 3.7 + (sheets - 15) * 0.35;
else if (sheets <= 35) return 0.38 + 3.7 + 3.5 + (sheets - 25) * 0.32;
else if (sheets <= 50) return 0.38 + 3.7 + 3.5 + 3.2 + (sheets - 35) * 0.3;
else return 0.38 + 3.7 + 3.5 + 3.2 + 3.0 + (sheets - 50) * 0.28;
}
double CalculateQualityDuplex(int pages) {
if (pages <= 6) return 0.35;
else if (pages <= 30) return 0.35 + (pages - 6) * 0.32;
else return 0.35 + 7.68 + (pages - 30) * 0.29;
}
// Premium A4 printing costs
double CalculatePremiumSingleSide(int sheets) {
if (sheets <= 5) return 0.39;
else if (sheets <= 25) return 0.39 + (sheets - 5) * 0.37;
else if (sheets <= 50) return 0.39 + 7.4 + (sheets - 25) * 0.35;
else return 0.39 + 7.4 + 8.75 + (sheets - 50) * 0.33;
}
double CalculatePremiumDuplex(int pages) {
if (pages <= 6) return 0.39;
else if (pages <= 50) return 0.39 + (pages - 6) * 0.36;
else return 0.39 + 15.84 + (pages - 50) * 0.33;
}
};
// Delivery fee mapping
const double deliveryFees[] = {0.0, 1.3, 1.5, 1.8, 2.1, 2.1, 1.7, 1.3, 1.3, 0.9, 1.6, 0.5, 0.7, 1.0, 1.3, 0.9, 1.3};
void ProcessPayment(int& count, double deliveryFee) {
PrintService ps;
double total = ps.CalculateQualitySingleSide(count) + deliveryFee;
cout << "\033[31;1mWaiting to print, total payment: \033[0m" << total << "\033[31;1m yuan\033[0m" << endl;
}
void ProcessDuplexPayment(int& count, double deliveryFee) {
PrintService ps;
double total = ps.CalculateQualityDuplex(count) + deliveryFee;
cout << "\033[31;1mWaiting to print, total payment: \033[0m" << total << "\033[31;1m yuan\033[0m" << endl;
}
void ProcessPremiumPayment(int& count, double deliveryFee) {
PrintService ps;
double total = ps.CalculatePremiumSingleSide(count) + deliveryFee;
cout << "\033[31;1mWaiting to print, total payment: \033[0m" << total << "\033[31;1m yuan\033[0m" << endl;
}
void ProcessPremiumDuplexPayment(int& count, double deliveryFee) {
PrintService ps;
double total = ps.CalculatePremiumDuplex(count) + deliveryFee;
cout << "\033[31;1mWaiting to print, total payment: \033[0m" << total << "\033[31;1m yuan\033[0m" << endl;
}
UI Functions .cpp
#include "MainSystem.h"
#include "UserInfo.h"
void PrintMainMenu() {
system("cls");
cout << "**********************************************" << endl;
cout << "* Welcome to this product *" << endl;
cout << "**********************************************" << endl;
cout << "* 1. Print *" << endl;
cout << "* 2. Info *" << endl;
cout << "* 3. Exit *" << endl;
cout << "**********************************************" << endl;
}
void PrintPrintModeMenu() {
cout << "**********************************************" << endl;
cout << "* Please select print mode *" << endl;
cout << "**********************************************" << endl;
cout << "* 1: B&W Single Side (sheet) - Quality *" << endl;
cout << "* 2: B&W Duplex (side) - Quality *" << endl;
cout << "* 3: Color Single Side (sheet) - Quality *" << endl;
cout << "* 4: Color Duplex (side) - Quality *" << endl;
cout << "**********************************************" << endl;
cout << "* 5: B&W Single Side (sheet) - Premium *" << endl;
cout << "* 6: B&W Duplex (side) - Premium *" << endl;
cout << "* 7: Color Single Side (sheet) - Premium *" << endl;
cout << "* 8: Color Duplex (side) - Premium *" << endl;
cout << "**********************************************" << endl;
cout << "* 9: Exit *" << endl;
cout << "**********************************************" << endl;
}
void PrintQualitySingleSideMenu() {
system("cls");
cout << "**********************************************" << endl;
cout << "* B&W Single Side Printing (Quality) *" << endl;
cout << "**********************************************" << endl;
cout << "* How many sheets do you need? *" << endl;
cout << "**********************************************" << endl;
int num = 0;
scanf_s("%d", &num);
while (getchar() != '\n');
PrintDeliveryPrompt();
int needDelivery = 0;
scanf_s("%d", &needDelivery);
if (needDelivery == 1) {
PrintShippingLocations();
int location = 0;
scanf_s("%d", &location);
while (getchar() != '\n');
if (location >= 1 && location <= 16) {
ProcessPayment(num, deliveryFees[location]);
} else {
cout << "Unknown dormitory, cannot provide delivery." << endl;
}
} else {
ProcessPayment(num, 0);
}
}
void PrintQualityDuplexMenu() {
system("cls");
cout << "**********************************************" << endl;
cout << "* B&W Duplex Printing (Quality) *" << endl;
cout << "**********************************************" << endl;
cout << "* How many sides do you need? *" << endl;
cout << "**********************************************" << endl;
int num = 0;
scanf_s("%d", &num);
while (getchar() != '\n');
PrintDeliveryPrompt();
int needDelivery = 0;
scanf_s("%d", &needDelivery);
if (needDelivery == 1) {
PrintShippingLocations();
int location = 0;
scanf_s("%d", &location);
while (getchar() != '\n');
if (location >= 1 && location <= 16) {
ProcessDuplexPayment(num, deliveryFees[location]);
} else {
cout << "Unknown dormitory, cannot provide delivery." << endl;
}
} else {
ProcessDuplexPayment(num, 0);
}
}
void PrintServiceUnavailable() {
cout << "**********************************************" << endl;
cout << "* Service not available, please re-enter.*" << endl;
cout << "**********************************************" << endl;
system("pause");
while (getchar() != '\n');
}
void PrintExitMenu() {
system("pause");
system("cls");
cout << "**********************************************" << endl;
cout << "* Are you sure you want to exit? *" << endl;
cout << "**********************************************" << endl;
cout << "* 1: Yes 2: No *" << endl;
cout << "**********************************************" << endl;
}
void PrintInvalidInput() {
cout << "**********************************************" << endl;
cout << "* Invalid input, please re-enter. *" << endl;
cout << "**********************************************" << endl;
system("pause");
while (getchar() != '\n');
}
void PrintPremiumSingleSideMenu() {
system("cls");
cout << "**********************************************" << endl;
cout << "* B&W Single Side Printing (Premium) *" << endl;
cout << "**********************************************" << endl;
cout << "* How many sheets do you need? *" << endl;
cout << "**********************************************" << endl;
int num = 0;
scanf_s("%d", &num);
while (getchar() != '\n');
PrintDeliveryPrompt();
int needDelivery = 0;
scanf_s("%d", &needDelivery);
if (needDelivery == 1) {
PrintShippingLocations();
int location = 0;
scanf_s("%d", &location);
while (getchar() != '\n');
if (location >= 1 && location <= 16) {
ProcessPremiumPayment(num, deliveryFees[location]);
} else {
cout << "Unknown dormitory, cannot provide delivery." << endl;
}
} else {
ProcessPremiumPayment(num, 0);
}
}
void PrintPremiumDuplexMenu() {
system("cls");
cout << "**********************************************" << endl;
cout << "* B&W Duplex Printing (Premium) *" << endl;
cout << "**********************************************" << endl;
cout << "* How many sides do you need? *" << endl;
cout << "**********************************************" << endl;
int num = 0;
scanf_s("%d", &num);
while (getchar() != '\n');
PrintDeliveryPrompt();
int needDelivery = 0;
scanf_s("%d", &needDelivery);
if (needDelivery == 1) {
PrintShippingLocations();
int location = 0;
scanf_s("%d", &location);
while (getchar() != '\n');
if (location >= 1 && location <= 16) {
ProcessPremiumDuplexPayment(num, deliveryFees[location]);
} else {
cout << "Unknown dormitory, cannot provide delivery." << endl;
}
} else {
ProcessPremiumDuplexPayment(num, 0);
}
}
void PrintShippingLocations() {
system("cls");
cout << "**********************************************" << endl;
cout << "* Please select delivery location *" << endl;
cout << "**********************************************" << endl;
cout << "* 1: 1A/1B *" << endl;
cout << "* 2: 2A/2B *" << endl;
cout << "* 3: 3A/3B *" << endl;
cout << "* 4: 4A/4B *" << endl;
cout << "* 5: Building 5 *" << endl;
cout << "* 6: Building 6 *" << endl;
cout << "* 7: Building 7 *" << endl;
cout << "* 8: Building 8 *" << endl;
cout << "* 9: Building 9 *" << endl;
cout << "* 10: Library *" << endl;
cout << "* 11: 11A/11B *" << endl;
cout << "* 12: 12A/12B *" << endl;
cout << "* 13: 13A/13B *" << endl;
cout << "* 14: 14A/14B *" << endl;
cout << "* 15: Building 15 *" << endl;
cout << "* 16: Building 16 *" << endl;
cout << "**********************************************" << endl;
}
void PrintDeliveryPrompt() {
system("cls");
cout << "**********************************************" << endl;
cout << "* Do you need delivery service? *" << endl;
cout << "**********************************************" << endl;
cout << "* 1: Yes *" << endl;
cout << "* 2: No *" << endl;
cout << "**********************************************" << endl;
}