본문 바로가기
학부공부/C_Basic

1. Project_KU Mobile Phone Bill Calculator[C Basic]

by sonpang 2021. 11. 7.
반응형

1.1. Environment

OS: Windows 10

IDE: Visual Studio 2017

Language: C (‘C’ only. If use any of ‘C++’, will get 0 point.)

 

1.2. KU Mobile Phone Bill Calculator

Your program should display the main menu providing following functions.

Display plans

Usage information for past two months

Input this month usage

Total fee for past 3 months

Best plan recommendation

Exit

A user can execute each function by entering corresponding number as input.

Each option must provide ‘back to main menu’ functionality as default.

 

Example of main menu

Displaying Plans

• Your program will displays two pre-defined plans. The two pre-defined plans are as follows.

You have to display pre-defined mobile billing plans

Past 2 months’ usage information

For the past two months, your program must display the following information for each month

User’s plan

Usage of voice

Usage of text

Usage of data

Current plan, and usages are determined randomly with following conditions when your program begins.

1) Current plan: one of pre-defined plans

2) Usages of voice: from 1 to 700 min

3) Usages of text: from 0 to 300 messages

4) Usages of data: from 0.50 to 150.00 GB

Input this month Usage

Input your usage of voice, text, and data for current month

1) Usages of voice

2) Usages of text messages

3) Usages of data

Fee of Past 3 Months

Your program must show billings for the past three months

Billings include the following information

  • Usage of voice, text, data for each month

  • Extra data that will be carried over to next month

    • If you consume data below free tier in a month, the unconsumed data can be carried over to the next month

    • But, the amount carried over cannot exceed 10% of the total amount of free tier in a month

    • Ex) Free tier = 30GB, used = 25GB, Carried over = 3GB

  • Fee of each month

Best plan recommendation

Your program must recommend the best plan based on user’s average usages of the past three months.

1) The best plan is the one providing service with the lowest total fee.

2) The best plan is determined based on the average usages for the past three months (including this month).

3) During the average usage calculations, round off to each unit of service.

Ex)  1st month: 350 min,   100 texts,    3.25 GB

     2nd month: 424 min,   200 texts,    2.15 GB

     3rd month: 200 min,     50 texts,  10.00 GB

        Average usages: 324 min,   116 texts,      5.13 GB

1.3. Note

When you want to clean CMD, you can use system(“cls“);.

<stdlib.h> includes this function.

 

 

1.4. Code

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define _CRT_SECURE_NO_WARNINGS

void Display_menu();
void Display_plans();
void Display_pastinfo(double LastData[][3], char MyPlan[][20], int MyPlanindex);
void Input_Usage(double NewData[][3]);
void Display_total(double Data[][3], char MyPlan[][20], int MyPlanindex);
void Display_recommendation(double Data[][3], char MyPlan[][20], int MyPlanindex);

int main()
{
	srand(time(NULL));
	int menu, MyPlanindex=rand()%2;
	char MyPlan[2][20] = { "Basic Plan","More Data Plan" };
	//The double type produces less errors than the float type.
	//Errors caused by floating point number types are not considered in this program.(by Margin_of_error.pdf)
	double Data[3][3] = { rand() % 700 + 1,rand() % 301, (rand() % 14950) / (double)100 + 0.50, rand() % 700 + 1,rand() % 301, (rand() % 14950) / (double)100 + 0.50 };
	
	//Menu confirmation and Function execution 
	while(1) {
		Display_menu();
		printf("Please select menu: ");
		if (scanf("%d", &menu) != 1) {
			fseek(stdin, 0, SEEK_END);//Processing when a character type is entered in menu. > Clear the buffer to induce re - entry.
			continue;
		}
		switch (menu) {
		case 1:
			Display_plans();
			break;
		case 2:
			Display_pastinfo(Data, MyPlan, MyPlanindex);
			break;
		case 3:
			Input_Usage(Data);
			break;
		case 4:
			Display_total(Data, MyPlan, MyPlanindex);
			break;
		case 5:
			Display_recommendation(Data, MyPlan, MyPlanindex);
			break;
		default:
			break;
		}
		if (menu == 6)
			break;
	}
	
	return 0;
}
void Display_menu() {
	system("cls");
	printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
	printf("┃       KU Mobile Phone Bill Calculator        ┃\n");
	printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
	printf("┃ 1. Display plans                             ┃\n");
	printf("┃ 2. Usage information for past two months     ┃\n");
	printf("┃ 3. Input this month usage                    ┃\n");
	printf("┃ 4. Total fee for past 3 months               ┃\n");
	printf("┃ 5. Best plan recommendation                  ┃\n");
	printf("┃ 6. Exit                                      ┃\n");
	printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
}

void Display_plans()
{
	char back_check;
	do {
		//Basic Plan
		system("cls");
		printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
		printf("┃                  Basic Plan                  ┃\n");
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃   Included in plan    ┃  Additional usages   ┃\n");
		printf("┣━━━━━━━━━━━┳━━━━━━━━━━━┻━━┳━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Voice     ┃ 500m free    ┃ \\ 50 / 1m         ┃\n");
		printf("┃ Text      ┃ 100t free    ┃ \\ 10 / 1t         ┃\n");
		printf("┃ Data      ┃ 2.00GB free  ┃ \\ 1000 / 0.1GB    ┃\n");
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Basic fee ┃ \\ 20000                          ┃\n");
		printf("┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");

		//More Data Plan
		printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
		printf("┃                 More Data Plan               ┃\n");
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃   Included in plan    ┃  Additional usages   ┃\n");
		printf("┣━━━━━━━━━━━┳━━━━━━━━━━━┻━━┳━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Voice     ┃ 300m free    ┃ \\ 10 / 1m         ┃\n");
		printf("┃ Text      ┃ 100t free    ┃ \\ 30 / 1t         ┃\n");
		printf("┃ Data      ┃ 30.00GB free ┃ \\ 500 / 0.1GB     ┃\n");
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Basic fee ┃ \\ 45000                          ┃\n");
		printf("┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
		printf("Back to main menu Y/N : ");
		scanf("%c", &back_check);
	}while(back_check!='Y');
}

void Display_pastinfo(double LastData[][3], char MyPlan[][20], int MyPlanindex)
{
	char back_check;
	do {
		//Last two months usage
		system("cls");
		printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
		printf("┃               Last two months usage               ┃\n");
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ My Plan : %-20s                    ┃\n", MyPlan[MyPlanindex]);
		printf("┣━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃           ┃     February      ┃       March       ┃\n");
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Voice     ┃        %4.0lf min   ┃        %4.0lf min   ┃\n", LastData[0][0], LastData[1][0]);
		printf("┃ Text      ┃        %4.0lf text  ┃        %4.0lf text  ┃\n", LastData[0][1], LastData[1][1]);
		printf("┃ Data      ┃      %6.2lf GB    ┃      %6.2lf GB    ┃\n", LastData[0][2], LastData[1][2]);
		printf("┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┛\n");
		printf("Back to main menu Y/N : ");
		scanf("%c", &back_check);
	} while (back_check != 'Y');
}

void Input_Usage(double NewData[][3])
{
	char back_check;
	system("cls");
	printf("==================================\n");
	printf("Input your usages of voice : ");
	scanf("%lf", &NewData[2][0]);
	printf("Input your usages of text  : ");
	scanf("%lf", &NewData[2][1]);
	printf("Input your usages of data  : ");
	scanf("%lf", &NewData[2][2]);
	do {
		printf("Back to main menu Y/N : ");
		scanf(" %c", &back_check);
	} while (back_check != 'Y');
}

void Display_total(double Data[][3], char MyPlan[][20], int MyPlanindex)
{
	char back_check;
	int i;
	double Extradata[3] = { 0 }, Totalfee[3] = { 0 }, Basefee, VoiceBaseline, TextBaseline, DataBaseline, VoiceAddcost, TextAddcost, DataAddcost;
	
	//Calculation Remaining Data and Total fee
	Basefee = MyPlanindex ? 45000 : 20000;
	VoiceBaseline = MyPlanindex ? 300 : 500;
	TextBaseline = MyPlanindex ? 100 : 100;
	DataBaseline = MyPlanindex ? 30 : 2;
	VoiceAddcost = MyPlanindex ? 10 : 50;
	TextAddcost = MyPlanindex ? 30 : 10;
	DataAddcost = MyPlanindex ? 500 : 1000;

	for (i = 0;i < 3;i++) {
		if (DataBaseline > Data[i][2])
			Extradata[i] = DataBaseline - Data[i][2];
		if (DataBaseline > Data[i][2] && Extradata[i] > DataBaseline / 10) //Limit of Extradata (amount carried over cannot exceed 10% of the total amount of free tier in a month)
			Extradata[i] = DataBaseline / 10;
	}
	for (i = 0;i < 3;i++) {
		Totalfee[i] += Basefee;
		if (Data[i][0] > VoiceBaseline)
			Totalfee[i] += (Data[i][0] - VoiceBaseline)*VoiceAddcost;
		if (Data[i][1] > TextBaseline)
			Totalfee[i] += (Data[i][1] - TextBaseline)*TextAddcost;
		if (i==0 && Data[i][2] > DataBaseline)
			Totalfee[i] += (Data[i][2] - DataBaseline) * 10 * DataAddcost;
		if (i>0 && Data[i][2] > DataBaseline + Extradata[i-1]) //Reflects Extradata (the unconsumed data can be carried over to the next month)
			Totalfee[i] += (Data[i][2] - DataBaseline) * 10 * DataAddcost;
	}

	do {
		system("cls");
		printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
		printf("┃                        My three months usage                          ┃\n");
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ My Plan : %-20s                                        ┃\n", MyPlan[MyPlanindex]);
		printf("┣━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃           ┃     February      ┃       March       ┃       April       ┃\n");
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Voice     ┃        %4.0lf min   ┃        %4.0lf min   ┃        %4.0lf min   ┃\n", Data[0][0], Data[1][0], Data[2][0]);
		printf("┃ Text      ┃        %4.0lf text  ┃        %4.0lf text  ┃        %4.0lf text  ┃\n", Data[0][1], Data[1][1], Data[2][1]);
		printf("┃ Data      ┃      %6.2lf GB    ┃      %6.2lf GB    ┃      %6.2lf GB    ┃\n", Data[0][2], Data[1][2], Data[2][2]);
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Extra Data┃      %6.2lf GB    ┃      %6.2lf GB    ┃      %6.2lf GB    ┃\n", Extradata[0], Extradata[1], Extradata[2]);
		printf("┣━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃ Extra Data┃      \\%10.0lf  ┃      \\%10.0lf  ┃      \\%10.0lf  ┃\n", Totalfee[0], Totalfee[1], Totalfee[2]);
		printf("┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━┛\n");
		printf("Back to main menu Y/N : ");
		scanf("%c", &back_check);
	} while (back_check != 'Y');
}

void Display_recommendation(double Data[][3], char MyPlan[][20], int MyPlanindex)
{
	char back_check;
	int  Totalfee[2] = { 20000, 45000 };
	double AverageData[3] = {(Data[0][0] + Data[1][0] + Data[2][0]) / 3 ,(Data[0][1] + Data[1][1] + Data[2][1]) / 3 ,(Data[0][2] + Data[1][2] + Data[2][2]) / 3 };
	//AverageData[2] = floor((AverageData[2]) * pow(10, 2) + 0.5f) / pow(10, 2);//Sum of Data/3 :This calculation causes a number to exceed two decimal places. And this result can produce unwanted values.
	
	//Calculation Basic Plan Fee
	if (AverageData[0] > 500)
		Totalfee[0] += (AverageData[0] - 500) * 50;
	if (AverageData[1] > 100)
		Totalfee[0] += (AverageData[1] - 100) * 10;
	if (AverageData[2] > 2)
		Totalfee[0] += (AverageData[2] - 2) *10 * 1000;
	//Calculation More Data Plan Fee
	if (AverageData[0] > 300)
		Totalfee[1] += (AverageData[0] - 300) * 10;
	if (AverageData[1] > 100)
		Totalfee[1] += (AverageData[1] - 100) * 30;
	if (AverageData[2] > 30)
		Totalfee[1] += (AverageData[2] - 30) * 10 * 500;

	do {
		//Average usage of 3-month and recommendation
		system("cls");		
		printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
		printf("┃              Average usage of 3-month             ┃\n");
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃  My Plan : %-20s                   ┃\n", MyPlan[MyPlanindex]);
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃  Average usage of voice : %5.0f                   ┃\n", AverageData[0]);
		printf("┃  Average usage of text  : %5.0f                   ┃\n", AverageData[1]);
		printf("┃  Average usage of data  : %5.2f                   ┃\n", AverageData[2]);
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃  Basic Plan Fee :      \\  %10d              ┃\n", Totalfee[0]);
		printf("┃  More Data Plan Fee :  \\  %10d              ┃\n", Totalfee[1]);
		printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");
		printf("┃  We recommend to use %-20s         ┃\n", Totalfee[0]<Totalfee[1]?"Basic Plan":"More Data Plan");
		printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
		printf("Back to main menu Y/N : ");
		scanf("%c", &back_check);
	} while (back_check != 'Y');
}

 

1.5. Results

 

반응형

'학부공부 > C_Basic' 카테고리의 다른 글

2. Project_64 PuyoPuyo[C Basic]  (0) 2021.11.07
1. Quiz[C Basic]  (0) 2021.11.07
10. File[C Basic]  (0) 2021.11.07
9. Struct[C Basic]  (0) 2021.11.07
8. Bit operator[C Basic]  (0) 2021.11.07

댓글