Y客地址

博客提供了Y客的地址为http://www.yeskee.com/fenglibing ,这是一个信息技术领域可能涉及网站相关的地址信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从您的描述来看,您正在设计一个基于控制台输入输出的“户信息系统”。这个系统的核心功能包括 **添加户**、**修改户**、**删除户** 和 **显示户列表**。下面是一个简要的设计说明以及一些关键点: --- ### 设计思路 #### 结构体定义 ```go type Customer struct { Id int // 户唯一标识符 Name string // 姓名 Gender string // 性别 Age int // 年龄 Phone string // 电话号码 Email string // 邮箱地址 } ``` 每个户的详细信息通过上述 `Customer` 结构体存储。 #### 功能模块划分 1. **主菜单** 提供用户选择操作的功能入口。 2. **添加户** 用户可以输入新户的姓名、性别、年龄、电话和邮箱等信息,并将其保存到系统的数据集合中(如切片数组)。 3. **修改户** 根据提供的户编号找到对应记录并允许更新其字段值。 4. **删除户** 按照指定编号查找目标户条目,并询问确认后移除该记录。 5. **展示所有户** 将已录入的所有户按表格形式打印出来,便于查看当前的数据状态。 --- ### 示例代码片段(Go语言) 以下是部分实现参考代码: ```go package main import ( "bufio" "fmt" "os" "strconv" ) // 定义结构体 type Customer struct { Id int Name string Gender string Age int Phone string Email string } var customers []Customer var idCounter = 1 func showMenu() { fmt.Println("---------------户信息管理软件----------------") fmt.Println("1 添加户") fmt.Println("2 修改户") fmt.Println("3 删除户") fmt.Println("4 查看户列表") fmt.Println("5 退出程序") fmt.Print("请选择(1-5): ") } func addCustomer(scanner *bufio.Scanner) { var name, gender, phone, email string var age int fmt.Println("\n> 添加户") fmt.Print("请输入姓名: ") scanner.Scan() name = scanner.Text() fmt.Print("请输入性别: ") scanner.Scan() gender = scanner.Text() fmt.Print("请输入年龄: ") scanner.Scan() age, _ = strconv.Atoi(scanner.Text()) fmt.Print("请输入电话: ") scanner.Scan() phone = scanner.Text() fmt.Print("请输入邮箱: ") scanner.Scan() email = scanner.Text() newCustomer := Customer{ Id: idCounter, Name: name, Gender: gender, Age: age, Phone: phone, Email: email, } customers = append(customers, newCustomer) idCounter++ fmt.Println("户添加成功!") } func listCustomers() { if len(customers) == 0 { fmt.Println("暂无户数据!") return } fmt.Printf("%-5s %-10s %-8s %-6s %-15s %-20s\n", "编号", "姓名", "性别", "年龄", "电话", "邮箱") for _, customer := range customers { fmt.Printf("%-5d %-10s %-8s %-6d %-15s %-20s\n", customer.Id, customer.Name, customer.Gender, customer.Age, customer.Phone, customer.Email) } } func modifyCustomer(scanner *bufio.Scanner) { fmt.Println("\n> 修改户") fmt.Print("请输入需要修改的户编号(-1返回上一级): ") scanner.Scan() inputId, err := strconv.Atoi(scanner.Text()) if inputId == -1 || err != nil { return } index := findIndexById(inputId) if index == -1 { fmt.Println("未找到匹配的户编号!") } else { oldCustomer := &customers[index] fmt.Printf("原信息 -> %v\n", oldCustomer) fmt.Printf("> 是否修改【%s】的信息(y/n)? ", oldCustomer.Name) scanner.Scan() confirm := scanner.Text() if confirm == "y" { fmt.Print("新的名字[留空则保持不变]: ") scanner.Scan() textName := scanner.Text() if textName != "" { oldCustomer.Name = textName } fmt.Print("新的性别[留空则保持不变]: ") scanner.Scan() textGender := scanner.Text() if textGender != "" { oldCustomer.Gender = textGender } fmt.Print("新的年龄[留空则保持不变]: ") scanner.Scan() textAge := scanner.Text() if textAge != "" { numAge, _ := strconv.Atoi(textAge) oldCustomer.Age = numAge } fmt.Print("新的电话[留空则保持不变]: ") scanner.Scan() textPhone := scanner.Text() if textPhone != "" { oldCustomer.Phone = textPhone } fmt.Print("新的邮件地址[留空则保持不变]: ") scanner.Scan() textEmail := scanner.Text() if textEmail != "" { oldCustomer.Email = textEmail } fmt.Println("户信息修改成功!") } } } func deleteCustomer(scanner *bufio.Scanner) { fmt.Println("\n> 删除户") fmt.Print("请输入需要删除的户编号(-1返回上一级): ") scanner.Scan() inputId, err := strconv.Atoi(scanner.Text()) if inputId == -1 || err != nil { return } index := findIndexById(inputId) if index == -1 { fmt.Println("未找到匹配的户编号!") } else { fmt.Printf("确定要删除户:%+v 吗?(y/n)", customers[index]) scanner.Scan() confirm := scanner.Text() if confirm == "y" { customers = append(customers[:index], customers[index+1:]...) fmt.Println("删除成功!") } else { fmt.Println("取消删除操作...") } } } func findIndexById(id int) int { for i, c := range customers { if c.Id == id { return i } } return -1 } func main() { scanner := bufio.NewScanner(os.Stdin) for { showMenu() scanner.Scan() option, _ := strconv.Atoi(scanner.Text()) switch option { case 1: addCustomer(scanner) case 2: modifyCustomer(scanner) case 3: deleteCustomer(scanner) case 4: listCustomers() case 5: fmt.Println("感谢使用本系统,再见!") os.Exit(0) default: fmt.Println("无效选项,请重新选择!") } } } ``` --- ### 输出示例 运行结果类似于以下内容: ``` ---------------户信息管理软件---------------- 1 添加户 2 修改户 3 删除户 4 查看户列表 5 退出程序 请选择(1-5): 1 ... ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值