Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Go Programming Provide a menu to allow the user to A Add a new vehicle registration, S Search for a vehicle registration, P Print all

Go Programming

Provide a menu to allow the user to A Add a new vehicle registration, S Search for a vehicle

registration, P Print all of the vehicle registration information for all vehicles, and Q Quit the

program.

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.

If the user enters P, all information should be displayed using a table with aligned columns and a table

header.

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).

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(details[i]) } case "S": fmt.Println("Search for a vechicle registration") var b string //fmt.Println(x[1])

//Asking the license which we want to search fmt.Println("Enter search License:") fmt.Scanln(&b) here:= make(map[string]int) for i:=0; i //x:=strings.Split(details[i]," ") //fmt.Println("nope", x[0]) //here[i]++ } case "Q": fmt.Println("Quit") default: fmt.Println("INVALID INPUT!!!") } } }

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions