Question #37723

You are going to implement a command-line student management system.
Users can type four commands (case insensitive):
 Create command to create new student record with 4 pieces of information separated by
comma: student ID (string), name (string), major (string), GPA (floating point)
o For example: create:105,Alice,EECS,2.54
 Sort command to display all the student records in sorted order either by name or by GPA (the
sorting criteria is case insensitive)
o For example: sort:name
 Search command to find a student record by the student ID
o For example: search:105
1

Expert's answer

2013-12-11T06:14:51-0500

Answer on Question#37723- Programming, C#

1. You are going to implement a command-line student management system.

Users can type four commands (case insensitive):

- Create command to create new student record with 4 pieces of information separated by comma: student ID (string), name (string), major (string), GPA (floating point)

o For example: create:105,Alice,EECS,2.54

- Sort command to display all the student records in sorted order either by name or by GPA (the sorting criteria is case insensitive)

o For example: sort:name

- Search command to find a student record by the student ID

o For example: search:105

Solution.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            PrintResult pr = new PrintResult();
            pr.Print();
            Console.Read();
        }
    }
    public class Student
    {
        public string ID;
        public string name;
        public string major;
        public double GPA;
        public void View()
        {
            Console.WriteLine(ID + " " + name + " " + major + " " + GPA);
        }
    }
}
class PrintResult
{
    SortedList<string, Student> std;
    public PrintResult()
    {
        std = new SortedList<string, Student>();
    }
    public void GetData()
    {
        Student stud = new Student();
        Console.WriteLine("Enter the ID of the student:");
        stud.ID = Console.ReadLine();
        Console.WriteLine("Enter the name of the student:");
        stud.name = Console.ReadLine();
        Console.WriteLine("Enter the major of the student:");
        stud.major = Console.ReadLine();
        Console.WriteLine("Enter the GPA of the student:");
        stud.GPA = Convert.ToDouble(Console.ReadLine());
        std.Add(stud.ID, stud);
        returnPrint();
    }
    public void Print()
    {
        Console.Clear();
        Console.WriteLine("Select the menu item:");
        Console.WriteLine("===================\n");
        Console.WriteLine("1. Create command to create new student record");
        Console.WriteLine("2. Sort command to display all the student records in sorted order either by name or by GPA");
        Console.WriteLine("3. Search command to find a student record by the student ID");
        Console.WriteLine("4. Show all students");
        string sMenu;
        sMenu = Console.ReadLine();
        switch (sMenu)
        {
            case "1":
                { GetData(); break; }
            case "2":
                { Sort(); break; }
            case "3":
                { Find(); break; }
            case "4":
                { AllView(); break; }
            default:
                { Console.WriteLine("Wrong the chosen menu item!"); returnPrint();
                break;
                }
        }
    }
    public void Find()
    {
        string s;
        s = Console.ReadLine();
        std[s].View();
        returnPrint();
    }
    public void AllView()
    {
        foreach (string s in std.Keys)
        {
            std[s].View();
        }
        returnPrint();
    }
    public void Sort()
    {
        SortedList s = new SortedList();
        Console.WriteLine("1.By Name " + "2. By GPA");
        if (Console.ReadLine() == "1")
        {
            foreach (string sid in std.Keys)
            {
                s.Add(std[sid].name, std[sid]);
            }
            for (int i = 0; i < s.Count; i++)
            {
                Console.WriteLine("{0}", s.GetKey(i).ToString());
            }
        }
        if (Console.ReadLine() == "2")
        {
            foreach (string sid in std.Keys)
            {
                s.Add(std[sid].GPA, std[sid]);
            }
            for (int i = 0; i < s.Count; i++)
            {
                Console.WriteLine("{0}", s.GetKey(i));
            }
        }
        returnPrint();
    }
    public void returnPrint()
    {
        Console.WriteLine("Return in main menu?\n" + "1. Yes " + "2. No");
        if (Console.ReadLine() == "1") { Print(); }
    }
}


You can also run the file in the attached file .exe

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
12.12.13, 14:16

Unfortunately, your question requires a lot of work and cannot be done for free. Submit it with all requirements as an assignment to our control panel and we'll assist you.

Assignment Expert
12.12.13, 14:15

You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

sandeep
11.12.13, 20:14

thank you for your reply

sandeep
11.12.13, 20:12

Instructions: Complete the following exercise. Your total assignment submission should be at least 3-4 pages in length, double spaced. Topic Summary: Implementing a new Software/Hardware Systems can be quite challenging. Imagine that you work for a company that has a traditional style Human Resources Department that does not offer any services via the Internet. This company decides to create an Employee Self Service system that uses internet technologies. Write an analysis of the steps you would take to so

LATEST TUTORIALS
APPROVED BY CLIENTS