Ask Question
11 October, 21:32

Write an application that allows a user to select a country from a list box that contains the following seven options. After the user makes a selection, display the country's capital city.

Country

Capital Austria

Vienna Canada

Toronto England

London France

Paris Italy

Rome Mexico

Mexico City Spain

Madrid

+1
Answers (1)
  1. 11 October, 23:24
    0
    Programming Language not stated;

    But this application definitely requires a graphical user interface platform (so, I'll use Microsoft Visual C# - Winforms).

    Controls to be used are.

    1. Form

    2. List box

    I'll name the Form, Form1 and the list box, listbox1.

    Explanation:

    The code goes thus;

    private void Form1_Load (object sender, System. EventArgs e)

    {

    //Load country into empty listbox

    listbox1. Items. Add ("Austria");

    listbox1. Items. Add ("Canada");

    listbox1. Items. Add ("England");

    listbox1. Items. Add ("France");

    listbox1. Items. Add ("Italy");

    listbox1. Items. Add ("Mexico");

    listbox1. Items. Add ("Spain");

    }

    private void listbox1_SelectedIndexChanged (object sender, System. EventArgs e)

    {

    //Check if an item is really selected

    if (listbox1. SelectedIndex > = 0)

    {

    //Index 0 represents 1st item that was added to the listbox and that's Austria

    if (listbox1. SelectedIndex = =0)

    {

    MessageBox. Show ("Vienna");

    }

    else if (listbox1. SelectedIndex = = 1)

    {

    MessageBox. Show ("Toronto");

    }

    else if (listbox1. SelectedIndex = =2)

    {

    MessageBox. Show ("London");

    }

    else if (listbox1. SelectedIndex = = 3)

    {

    MessageBox. Show ("Paris");

    }

    else if (listbox1. SelectedIndex = =4)

    {

    MessageBox. Show ("Rome");

    }

    else if (listbox1. SelectedIndex = = 5)

    {

    MessageBox. Show ("Mexico City");

    }

    else if (listbox1. SelectedIndex = = 6)

    {

    MessageBox. Show ("Madrid");

    }

    }

    else

    {

    MessageBox. Show ("No item selected");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write an application that allows a user to select a country from a list box that contains the following seven options. After the user makes ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers