Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#define _CRT_SECURE_NO_WARNINGS #include #include #include #include account.h #include ticket.h #include commonHelpers.h #include accountTicketingUI.h void displayMenuAgent() { printf(============================================== ); printf(Account Ticketing System - Agent Menu );

#define _CRT_SECURE_NO_WARNINGS #include  #include  #include  #include "account.h" #include "ticket.h" #include "commonHelpers.h" #include "accountTicketingUI.h" void displayMenuAgent() { printf("============================================== "); printf("Account Ticketing System - Agent Menu "); printf("============================================== "); printf(" 1) Add a new account "); printf(" 2) Modify an existing account "); printf(" 3) Remove an account "); printf(" 4) List accounts: summary view "); printf(" 5) List accounts: detailed view "); printf("---------------------------------------------- "); printf(" 6) List new tickets "); printf(" 7) List active tickets "); printf(" 8) List closed tickets "); printf(" 9) Manage a ticket "); printf("10) Archive closed tickets "); printf("---------------------------------------------- "); printf("11) View archived account statistics "); printf("12) View archived tickets statistics "); printf("---------------------------------------------- "); printf("0) Logout "); return; } void displayMenuCustomer() { printf("============================================== "); printf("Customer Main Menu "); printf("============================================== "); printf("1) View your account detail "); printf("2) Create a new ticket "); printf("3) Modify an active ticket "); printf("4) List my tickets "); printf("---------------------------------------------- "); printf("0) Logout "); return; } void displayAccountSummaryHeader() { printf(" Acct# Acct.Type Birth "); printf("----- --------- ----- "); return; } void displayAccountDetailHeader() { printf("Acct# Acct.Type Birth Income Country Disp.Name Login Password "); printf("----- --------- ----- ----------- ---------- --------------- ---------- -------- "); return; } void dispalyAccountSummaryRecord(const ACCOUNT account[]) { printf("%05d %-9s %5d ", account->account_number, account->account_type == 'A' ? "AGENT" : "CUSTOMER", account->demographic.birth_year); return; } void dispalyAccountDetailRecord(const ACCOUNT account[]) { char password[9] = { 0 }; char country[31] = { 0 }; int i; for (i = 0; i < 30; i++) { country[i] = toupper(account->demographic.country[i]); } for (i = 0; i < 8; i++) { if (i % 2) password[i] = '*'; else password[i] = account->userLogin.password[i]; } printf("%05d %-9s %5d $%10.2lf %-10s %-15s %-10s %8s ", account- >account_number, account->account_type == 'A' ? "AGENT" : "CUSTOMER", account- >demographic.birth_year, account->demographic.income, country, account- >userLogin.customer_name, account->userLogin.login_name, password); return; } void displayAllAccountSummaryRecords(const ACCOUNT* account, int arrsize) { int i; displayAccountSummaryHeader(); for (i = 0; i < arrsize; i++) { if (account[i].account_number != 0) dispalyAccountSummaryRecord(&account[i]); } printf(" "); pauseExecution(); return; } void displayAllAccountDetailRecords(const ACCOUNT* account, int arrsize) { int i; printf(" "); displayAccountDetailHeader(); for (i = 0; i < arrsize; i++) { if (account[i].account_number != 0) dispalyAccountDetailRecord(&account[i]); } printf(" "); pauseExecution(); return; } void displayTicketSummaryHeader() { printf("------ ------ ------------------------------ -------- "); printf("Ticket Status Subject Messages "); printf("------ ------ ------------------------------ -------- "); return; } void displayTicketDetailHeader() { printf("------ ----- --------------- ------ -------------------------------------- "); printf("Ticket Acct# Display Name Status Subject Messages "); printf("------ ----- --------------- ------ -------------------------------------- "); return; } void displayTicketSummaryRecord(const TICKET ticket[]) { printf("%06d %-6s %-30s %2d ", ticket->ticket_number, ticket->ticket_status == 1 ? "ACTIVE" : "CLOSED", ticket->subject, ticket->num_msg); return; } void displayTicketDetailRecord(const TICKET ticket[]) { printf("%06d %05d %-15s %-6s %-30s %2d ", ticket->ticket_number, ticket->ticket_account_number, ticket->type_msg->display_name, ticket->ticket_status == 1 ? "ACTIVE" : "CLOSED", ticket->subject, ticket->num_msg); return; } void displayAllTicketsSummaryRecord(const TICKET* ticket, int arrsize, int acct_num) { int i; displayTicketSummaryHeader(); for (i = 0; i < arrsize; i++) { if (ticket[i].ticket_account_number == acct_num) displayTicketSummaryRecord(&ticket[i]); } return; } void displayAllTicketsDetailRecord(const TICKET* ticket, int arrsize, int acct_num) { int i; displayTicketDetailHeader(); for (i = 0; i < arrsize; i++) { if (ticket[i].ticket_account_number == acct_num) displayTicketDetailRecord(&ticket[i]); } return; } int isAgent(ACCOUNT account) { if (account.account_type == 'A') { return 1; } return 0; } void printTicketMessage(TICKET* ticket, int index) { int i; printf(" ================================================================================ "); printf("%06d (%s) Re: %s ", ticket[index].ticket_number,ticket[index].ticket_status == 1 ? "ACTIVE" : "CLOSED", ticket[index].subject); printf("================================================================================ "); for (i = 0; i < ticket[index].num_msg; i++) { printf("%s (%s): ", ticket[index].type_msg[i].account_type == 'A' ? "AGENT" : "CUSTOMER", ticket[index].type_msg[i].display_name); if ((i % 5 == 4) && (i != 19) && (5 < ticket[index].num_msg)) { printf(" %s ", ticket[index].type_msg[i].msg_details); pauseExecution(); } else printf(" %s ", ticket[index].type_msg[i].msg_details); } return; } void applicationStartup(ACCOUNTTICKETINGDATA* data) { int index; do { index = menuLogin(data->accounts, data->ACCOUNT_MAX_SIZE); if (index >= 0) { if (isAgent(data->accounts[index])) { menuAgent(data, &data->accounts[index]); } else { printf(" "); menuCustomer(data->tickets, data->TICKET_MAX_SIZE, &data- >accounts[index]); //pauseExecution(); } } } while (index >= 0); printf(" ============================================== "); printf("Account Ticketing System - Terminated "); printf("============================================== "); return; return; } int menuLogin(ACCOUNT account[], int arrsize) { int choice, index, done = 0, attempts = 0; do { printf("============================================== "); printf("Account Ticketing System - Login "); printf("============================================== "); printf("1) Login to the system "); printf("0) Exit application "); printf("---------------------------------------------- "); printf("Selection: "); choice = getIntFromRange(0, 1); switch (choice) { case 0: printf(" Are you sure you want to exit? ([Y]es|[N]o): "); if (toupper(getCharOption("yYnN")) == 'Y') { done = 1; index = -1; } break; case 1: while (badLogin(account, arrsize, &index) && attempts <= 2) { attempts++; printf("INVALID user login/password combination! [attempts remaining:%d] ", 3 - attempts); if (attempts == 3) break; } if (attempts >= 2) { printf(" ERROR: Login failed! "); clearStandardInputBuffer(); pauseExecution(); attempts = 0; } else done = 1; break; } } while (done != 1); return index; } void menuAgent(ACCOUNTTICKETINGDATA* data, const ACCOUNT* paccount) { int selection, acct_num; printf(" "); do { printf("AGENT: %s (%d) ", paccount->userLogin.customer_name, paccount- >account_number); displayMenuAgent(); printf("Selection: "); selection = getIntFromRange(0, 12); switch (selection) { case 1: addNewAccount(data->accounts, data->ACCOUNT_MAX_SIZE); break; case 2: modifyAccount(data->accounts, data->ACCOUNT_MAX_SIZE); break; case 3: acct_num = removeAccount(data->accounts, data- >ACCOUNT_MAX_SIZE, paccount); if (acct_num > 0) { archiveClosedTicketsForAccount(data->tickets, data->TICKET_MAX_SIZE, acct_num); removeTicketsForAcctNum(data->tickets, data->TICKET_MAX_SIZE, acct_num); } else removeTicketsForAcctNum(data->tickets, data- >TICKET_MAX_SIZE, acct_num); break; case 4: displayAllAccountSummaryRecords(data->accounts, data->ACCOUNT_MAX_SIZE); break; case 5: displayAllAccountDetailRecords(data->accounts, data->ACCOUNT_MAX_SIZE); break; case 6: printf(" "); listNewTicketsAndMessages(data->tickets, data->TICKET_MAX_SIZE); break; case 7: listActiveTicketsAndMessages(data->tickets, data->TICKET_MAX_SIZE); break; case 8: listClosedTicketsAndMessages(data->tickets, data->TICKET_MAX_SIZE); break; case 9: manageTicket(data->tickets, data->TICKET_MAX_SIZE, paccount); break; case 10: archiveClosedTickets(data->tickets, data->TICKET_MAX_SIZE); break; case 11: viewArchivedAccountStatistics(); break; case 12: viewArchivedTicketStatistics(); break; case 0: printf(" Saving session modifications... "); printf("%4d account saved. ", saveAccounts(data->accounts, data->ACCOUNT_MAX_SIZE)); printf("%4d tickets saved. ", saveTickets(data->tickets, data->TICKET_MAX_SIZE)); printf("### LOGGED OUT ### "); break; default:printf("ERROR: Value must be between 0 and 12 inclusive: "); break; } } while (selection != 0); return; } void menuCustomer(TICKET* ticket, int arrsize, const ACCOUNT* paccount) { int selection; do { printf("CUSTOMER: %s (%d) ", paccount->userLogin.customer_name, paccount->account_number); displayMenuCustomer(); printf("Selection: "); selection = getIntFromRange(0, 4); printf(" "); switch (selection) { case 1: viewAccountDetails(paccount); break; case 2: createNewTicket(ticket, arrsize, paccount->account_number, paccount->userLogin.customer_name); break; case 3: modifyActiveTicket(ticket, arrsize, paccount->account_number, paccount->userLogin.customer_name, paccount->account_type); break; case 4: listMyTickets(ticket, arrsize, paccount->account_number); break; case 0: printf("Saving session modifications... "); printf(" %4d tickets saved. ", saveTickets(ticket, arrsize)); printf("### LOGGED OUT ### "); break; default: printf("ERROR: Value must be between 0 and 4 inclusive: "); break; } } while (selection != 0); return; }
account.h
#define _CRT_SECURE_NO_WARNINGS // SYSTEM LIBRARY #include  #include  #include "commonHelpers.h" // Function 1: currentYear int currentYear(void) { time_t currentTime = time(NULL); return localtime(¤tTime)->tm_year + 1900; } //===========================End Function 1==================================// // Function 2: clearStandardInputBuffer void clearStandardInputBuffer(void) { do { ; } while (getchar() != ' '); } //===========================End Function 2==================================// // Function 3: getInteger // Check for Entered and returned integer value. int getInteger(void) { int get_integer = 0; char new_line = 0; while (new_line != ' ') { scanf("%d%c", &get_integer, &new_line); if (new_line != ' ') { clearStandardInputBuffer(); printf("ERROR: Value must be an integer: "); } } return get_integer; } //===========================End Function 3==================================// // Function 4: getPositiveInteger // Check for Entered and returned a positive integer value. int getPositiveInteger(void) { int count = 1; int positiveInteger = 0; while (count) { positiveInteger = getInteger(); if (positiveInteger <= 0) { printf("ERROR: Value must be a positive integer greater than zero: "); } else { count = 0; } } return positiveInteger; } //===========================End Function 4==================================// // Function 5: getDouble // Check for Entered and returned a double value. double getDouble(void) { double doubleNum = 0.0; char new_line = 0; do { scanf("%lf%c", &doubleNum, &new_line); if (new_line != ' ') { clearStandardInputBuffer(); printf("ERROR: Value must be a double floating-point number: "); } } while (new_line != ' '); return doubleNum; } //===========================End Function 5==================================// // Function 6: getPositiveDouble // Check for Entered and returned a positive double value. double getPositiveDouble(void) { double doublePosNum = 0.0; int count = 1; while (count) { doublePosNum = getDouble(); if (doublePosNum > 0) { count = 0; } else { printf("ERROR: Value must be a positive double floating-point number: "); } } return doublePosNum; } //===========================End Function 6==================================// // Function 7: getIntFromRange // Guarantee an integer value is entered within the range (inclusive) and //returned. int getIntFromRange(int lower_bound, int upper_bound) { int int_range = 0; int count = 1; while (count) { int_range = getInteger(); if (int_range < lower_bound || int_range > upper_bound) { printf("ERROR: Value must be between %d and %d inclusive: ", lower_bound, upper_bound); } else { count = 0; } } return int_range; } //===========================End Function 7==================================// // Function 8: getCharOption // Guarantee a single character value is entered within the list of valid //characters and returned. char getCharOption(const char checkStringValue[]) { char enterChar = 0; int i = 0; int count = 1; int keepRecording = 0; char enterChar1 = 0; for (i = 0; checkStringValue[i] != '\0'; i++) { keepRecording++; } while (count) { scanf("%c%c", &enterChar, &enterChar1); if (enterChar1 == ' ') { for (i = 0; i < keepRecording && count; i++) { if (enterChar == checkStringValue[i]) { count = 0; } } if (count) { printf("ERROR: Character must be one of [%s]: ", checkStringValue); } } else { printf("ERROR: Character must be one of [%s]: ", checkStringValue); clearStandardInputBuffer(); } } return enterChar; } //===========================End Function 8==================================// // Function 9: getCString // Guarantees a C string value is entered containing the number of characters //within the range specified by the 2nd and 3rd arguments. void getCString(char charPointer[], int minimumChar, int maximumChar) { int j = 0, k = 0; int keepRecording = 0; int count = 1; char inputCString[500]; do { scanf("%500[^ ]", inputCString); clearStandardInputBuffer(); keepRecording = 0; for (j = 0; inputCString[j] != '\0'; j++) { keepRecording++; } if (keepRecording < minimumChar && (minimumChar != maximumChar)) { printf("ERROR: String length must be between %d and %d chars: ", minimumChar, maximumChar); } else if (keepRecording > maximumChar && (minimumChar != maximumChar)) { printf("ERROR: String length must be no more than %d chars: ", maximumChar); } else if ((keepRecording  maximumChar) && minimumChar == maximumChar) { printf("ERROR: String length must be exactly %d chars: ", minimumChar); } else { for (k = 0; k < keepRecording + 1; k++) { charPointer[k] = inputCString[k]; } count = 0; } } while (count); }

account.c

#include  #include "account.h" #include "commonHelpers.h" #include "accountTicketingUI.h" void getAccount(struct Account* account) { printf(" Account Data:New Record "); printf("--------------------------------------------------- "); printf(" Enter the account number: "); account->account_number = getInterger(); printf(" Enter the account type (A=Agent | C=Customer): "); account->account_type = getCharOption("AC"); return account; } void getUserLogin(struct UserLogin* login) { printf(" User Login Data Input "); printf("--------------------------------------------------- "); printf("Enter the user login ID: "); getCString(login->user_name, 1, 30); printf(" Enter the user display name: "); getCString(login->login_name, 1, 10); printf(" Enter the user login password: "); getCString(login->password, 1, 8); return login; } void getDemographic(struct Demographic* demo) { printf(" Demographic Data Input "); printf("--------------------------------------------------- "); printf("Enter the account holder's birth year: "); demo->birth_year = getInterger(); printf(" Enter the household income: "); demo->household_income = getDouble(); printf(" Enter the country where account holder lives: "); getCString(demo->represent_country, 1, 30); return demo; } void updateAccount(struct Account* account) { int choice = 1; while (choice != 0) { printf("Account: %d - Update Options "); printf("--------------------------------------------------- "); printf("1) Update account type (current value: %s) ", account->account_type); printf("2) Login"); printf("3) Demographics"); printf("0) Done"); printf("Selection: "); int option = getIntFromRange(0, 3); switch (option) { case 1: printf("ENTER account type (A or C only): ") account->account_type = getCharOption("AC"); break; case 2: updateUserLogin(); break; case 3: updateDemographic(); break; case 0: choice = 0; return account; break; } }; } void updateUserLogin(struct UserLogin* login) { int choice = 1; while (choice != 0) { printf("User Login: %s - Update Options "); printf("--------------------------------------------------- "); printf("1) Display name (current value: %s) ", login->login_name); printf("2) Password"); printf("0) Done"); printf("Selection: "); int option = getIntFromRange(0, 2); switch (option) { case 1: printf("ENTER new display name: "); login->login_name = getCString(login->login_name, 1, 10); break; case 2: printf("ENTER new password: "); login->password = getCString(login->password, 1, 10); break; case 0: choice = 0; return login; break; } }; return; } void updateDemographic(struct Demographic* demo) { int choice = 1; while (choice != 0) { printf("User Login: %s - Update Options "); printf("--------------------------------------------------- "); printf("1) Household Income (current value: %s) ", demo->household_income); printf("2) Country"); printf("0) Done"); printf("Selection: "); int option = getIntFromRange(0, 2); switch (option) { case 1: printf("ENTER new household income: "); demo->household_income = getDouble(); break; case 2: printf("ENTER new country: "); demo->represent_country = getCString(demo -> represent_country, 1, 30); break; case 0: choice = 0; return demo; break; } }; return; }

commonHelper.h

int currentYear(void); void clearStandardInputBuffer(void); //Check for Entered and returned integer value. int getInteger(void); //Check for Entered and returned a positive integer value. int getPositiveInteger(void); //Check for Entered and returned a double value. double getDouble(void); //Check for Entered and returned a positive double value. double getPositiveDouble(void); //guarantee an integer value is entered within the range (inclusive) and returned. int getIntFromRange(int lower_bound, int upper_bound); //Guarantee a single character value is entered within the list of valid characters //and returned. char getCharOption(const char checkStringValue[]); //guarantees a C string value is entered containing the number of characters within //the range specified by the 2nd and 3rd arguments. void getCString(char charPointer[], int minimumChar, int maximumChar); accountTicketingUI.h #ifndef ACCOUNT_TICKETING_UI_H_ #define ACCOUNT_TICKETING_UI_H_ void displayAccountSummaryHeader(void); void displayAccountDetailHeader(void); void displayAccountSummaryRecord(const struct Account*account); void displayAccountDetailRecord(const struct Account *account); void applicationStartup(struct Account accounts[], int arrSize); int menuLogin(const struct Account accounts[], int arrSize); void menuAgent(struct Account accounts[], int arrSize, const struct Account *account); int findAccountIndexByAcctNum(int acc_num, const struct Account accounts[], int arrSize, int type); void displayAllAccountSummaryRecords(const struct Account accounts[], int arrSize); void displayAllAccountDetailRecords(const struct Account accounts[], int arrSize); void pauseExecution(void); #endif // !ACCOUNT_TICKETING_UI_H_

a1ms4.c

// ####################################################################### // **************************************************************************** // **************************************************************************** // **************************************************************************** // DO NOT MODIFY THIS FILE!!!! // **************************************************************************** // **************************************************************************** // **************************************************************************** #define _CRT_SECURE_NO_WARNINGS // System Libraries #include  // User Libraries #include "account.h" #include "accountTicketingUI.h" // Macro's: helpers for default data #define ACCOUNT_SIZE 50 #define INIT_DATA_SIZE 5 // Function Prototype for populating some default values void populateAccounts(struct Account accounts[], int arrSize); // Main entry-point to the application int main(void) { struct Account accounts[ACCOUNT_SIZE] = { {0} }; // setup some test accounts: populateAccounts(accounts, ACCOUNT_SIZE); // launch application logic applicationStartup(accounts, ACCOUNT_SIZE); return 0; } void populateAccounts(struct Account accounts[], int arrSize) { int i, max = arrSize < INIT_DATA_SIZE ? arrSize : INIT_DATA_SIZE; struct Account tmp[INIT_DATA_SIZE] = { { 50001, 'C', {"Silly Sally", 1990, 150000.10, "CANADA"}, {"", ""} }, { 50028, 'A', {"Fred Flintstone", 1972, 2250400.22, "AFRICA"}, {"Bedrock-10", "yabadaba"} }, { 50004, 'C', {"Betty Boop", 1978, 250800.74, "INDIA"}, {"", ""}}, { 50008, 'A', {"Will Smith", 1952, 2350600.82, "U.S.A."}, {"MIBAgent-J", "theboss1"} }, { 50020, 'C', {"Shrimpy Shrimp", 2000, 350500.35, "KOREA"}, {"", ""} } }; for (i = 0; i < max; i++) { accounts[i] = tmp[i]; } }

commonHelpers.c

 struct Account { int account_no; char account_type; }; struct UserLogin { char uPassword[10], uLogin[10]; }; struct Person { char Person [10]; int birth_year; double IncomeOfHouse; char country[10]; char customer_name[31]; };

ticket.h

#pragma once #ifndef _TICKET_H_ #define _TICKET_H_ #include "accountTicketingUI.h" struct Message { char account_type[2]; char author[30]; char message_detail[150]; }; struct Ticket { int ticket_id; int customer_id; int status; //0 represents closed and 1 represent active (still open) char subject[30]; int message_count; struct Message *messages; }; void getTicket(struct Ticket* ticket); void getMessageTicket(struct Ticket* ticket); char* getTicketStatus(struct Ticket* ticket); void getListNewTicket(struct AccountTicketingData* accountTicketingData); void getListActiveTicket(struct AccountTicketingData* accountTicketingData); void getTicketAccount(struct AccountTicketingData* accountticketingdata, struct Account* account); #endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions