当前位置:网站首页>Customer information management system - C language
Customer information management system - C language
2022-06-13 05:06:00 【Jason_ LH1024】
Simulate the implementation of a text-based interface 《 Customer information management software 》
#include<stdio.h>
#include<string.h>
// Define the structure data type
struct Customer{
int id; // Number
int age;
char name[10];
char gender;// Gender w Woman m male
char phone[16];// Phone number
char email[20];// mailbox
};
int loop=1;// Controls whether to exit the main menu
char key;
int customerNum = 0;// Indicates the current number of customers
char choice=' ';
// Customer structure array
struct Customer customer[100];// At most 100 individual , Over expandable
// Display information about a customer variable Structure pointer
void getCustomerInfo(struct Customer *customer){
printf("\n%d\t%s\t%c\t%d\t%s\t%s",(*customer).id,(*customer).name,(*customer).gender,(*customer).age,(*customer).phone,(*customer).email);
}
void add(){
customer[customerNum].id=customerNum+1;
printf("------------------ Add customers ------------------");
printf("\n Please enter a name :");
scanf("%s",customer[customerNum].name);
getchar();
printf("\n Please enter gender :");
scanf("%c",&(customer[customerNum].gender));
getchar();
printf("\n Please enter age :");
scanf("%d",&(customer[customerNum].age));
getchar();
printf("\n Please input the phone number :");
scanf("%s",customer[customerNum].phone);
getchar();
printf("\n Please enter email address :");
scanf("%s",customer[customerNum].email);
getchar();
printf(" The addition is complete !");
customerNum++;
}
int findId(int id){
int index =-1;
for(int i=0;i<customerNum;i++){
if(customer[i].id==id){
index = i;
}
}
return index;
}
int del(int id){
int i;
int index = findId(id);
if(index==-1){ // Indicates that there is no id This customer
return 0;// Can't delete
}else{
for(i=index+1;i<customerNum;i++){
customer[i-1]=customer[i];
}
customerNum--;
return 1; // Delete successful
}
}
// Display the interface for deleting users . And then call
void delView(){
int id=0;
char choice=' ';
printf("\n-------------- Delete customer ---------------");
printf("\n Please select the number to be deleted (-1 sign out ):");
scanf("%d",&id);
getchar();
if(id==-1){
printf("\n-------- You gave up deleting ---------");
return;
}
printf("\n Confirm whether to delete (Y/N):");
scanf("%c",&choice);
getchar();
if(choice=='Y'){
if(del(id)==0){
printf("\n-------- Delete failed ,id non-existent ---------");
} else{
printf("\n-------- Delete successful ---------");
}
}
}
// Display a list of customer information
void listCustomer(){
int i = 0;
printf("\n------------------ Customer list ------------------");
printf("\n Number \t full name \t Gender \t Age \t Telephone \t mailbox ");
for(i=0;i<customerNum;i++){
getCustomerInfo(&customer[i]);
}
printf("\n--------------------------------------------");
}
int revise(int id){
int i;
char *str;
int index = findId(id);
if(index==-1){ // Indicates that there is no id This customer
return 0;// Do not modify
}else{
printf("\n The list of user information displayed is as follows ") ;
listCustomer();
printf("\n Please enter the name of the option you want to modify :");
scanf("%s",str);
if(strcmp(str," name ")==0){
printf("\n Please enter the name you want to change :");
scanf("%s",customer[index].name);
getchar();
}else if(strcmp(str," Age ")==0){
printf("\n Please enter the age you want to modify :");
scanf("%d",&(customer[index].age));
getchar();
}else if(strcmp(str," Gender ")==0){
printf("\n Please enter the gender you want to change :");
scanf("%s",&(customer[index].gender));
getchar();
}else if(strcmp(str," Telephone ")==0){
printf("\n Please enter the phone number you want to modify :");
scanf("%s",customer[index].phone);
getchar();
}else {
printf("\n Please enter the email you want to modify :");
scanf("%s",customer[index].email);
getchar();
}
}
return 1; // Delete successful
}
void reviseView(){
int id=0;
char choice=' ';
printf("\n-------------- Modify customer ---------------");
printf("\n Please select the number to be modified (-1 sign out ):");
scanf("%d",&id);
getchar();
if(id==-1){
printf("\n-------- You abandoned the modification ---------");
return;
}
printf("\n Confirm whether to modify (Y/N):");
scanf("%c",&choice);
getchar();
if(choice=='Y'){
if(revise(id)==0){
printf("\n No customer information ! Please add before modifying !");
printf("\n-------------------------------------");
} else{
printf("\n-------- Modification successful ---------");
listCustomer();
}
}
}
// Show main menu
void mainMenu(){
do{
printf("\n------------- Customer information management software ---------------");
printf("\n 1 Add customers ");
printf("\n 2 Modify customer ");
printf("\n 3 Delete customer ");
printf("\n 4 Customer list ");
printf("\n 5 refund Out ");
printf("\n--------------------------------------------");
printf("\n Please select (1-5): ");
scanf("%c",&key);
getchar();
switch(key){
case'1':
add();
break;
case'2':
reviseView();
break;
case'3':
delView();
break;
case'4':
listCustomer();
break;
case'5':
do{
printf("\n Confirm whether to delete (Y/N):");
scanf("%c",&choice);
getchar();
}while(choice!='Y'&&choice!='N');
if(choice='Y'){
loop=0;
}
break;
default:
printf("\n Your input is wrong , Please re-enter (1-5):");
break;
}
}while(loop);
printf(" You have exited the customer management system !");
getchar();
}
int main(){
mainMenu(); // Call function , Show menu
}


边栏推荐
- About anonymous inner classes
- Clause 33: decltype is used for auto & type formal parameters, with std:: forward
- Article 49: understanding the behavior of new handler
- QT signal is automatically associated with the slot
- JS to realize the conversion between string and array and an interview question
- shell变量学习笔记
- Understanding inode
- Simple SR: best buddy Gans for highly detailed image super resolution
- Spread your wings and soar
- Wang Dao Chapter II linear table exercises
猜你喜欢

Advanced C language - Section 1 - data storage

2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation

Embedded hardware: electronic components (1) resistance capacitance inductance

C language exercise 1

OpenCV中的saturate操作(饱和操作)究竟是怎么回事

RTSP streaming using easydarwin+ffmpeg

详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果

Mind mapping series - Database

Stepping on a horse (one stroke)

Leetcode game 297 (20220612)
随机推荐
Binary search and binary answer
C language learning log 10.4
QT interface rendering style
CMB's written test -- data analysis
Simple greedy strategy
C language exercise 1
Chapter 17 free space management
Force deduction 121 questions
Article 49: understanding the behavior of new handler
Regular expressions in QT
17.6 unique_ Lock details
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
【多线程编程】Future接口获取线程执行结果数据
Solution to sudden font change in word document editing
Luogu p1088 Martians
2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
Clause 34: lambda is preferred over std:: bind
COAP protocol libcoap API
Embedded hardware: electronic components (1) resistance capacitance inductance
OJ problem solution summary