Question
If the user enters A, the user should enter a license plate. If the plate has already been entered, a message should be displayed. If
If the user enters A, the user should enter a license plate. If the plate has already been entered, a message should be displayed. If not, the user should enter first name, last name, and phone number using three separate prompts. The item must be inserted using Sprintf.
If the user enters S, the user should enter a license plate. If the plate does not exist, a message should be displayed. If it does exist, the user information (first, last, phone) should be displayed.
When displaying results of search and print, you must use the Split function to break up the three pieces of data into their respective parts (first name, last name, phone number).
map will must be used for searching map.
package main
import( "fmt" "bufio" "os" "log" "strings"
) func main() { var num int var details []string for j:=0; j<2; j++{ fmt.Print("A- Add a new vehicle registration P- Print all of the vechicle registration infomation S-Search for a vehicle reigstration Q-Quit the program ") fmt.Print("Enter from the options above: ") reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString(' ') if err != nil{ log.Fatal(err) }
input = strings.TrimSpace(input)
Input:=strings.ToUpper(input)
switch Input{ case "A": var lic,f_name,l_name,phn string
fmt.Println("Add new vechicle registration") fmt.Println("Enter a license plate number:") fmt.Scan(&num) var i,flag int flag=0//is used to know the user present //This loop is used to search for the license for i=0;i fmt.Print("Enter Last name: ") fmt.Scanln(&l_name) fmt.Print("Enter Phone number: ") fmt.Scanln(&phn) //sprintf is used for formmating the input x:=fmt.Sprintf("%s %s %s %s",lic,f_name,l_name,phn) fmt.Println(x) //the new regestration will be added to the previous one using append details=append(details,x) } case "P": fmt.Println("Print all of the vehicle registration info") var i int //Traversing through the list of regestrations and they will be displayed for i=0;i fmt.Println("Search for a vechicle registration") var b string //Asking the license which we want to search fmt.Println("Enter search License:") fmt.Scanln(&b) } case "Q": fmt.Println("Quit") default: fmt.Println("INVALID INPUT!!!") } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started