Question

C# Write a program that takes a list of information and grades of the students of...

C#

Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program.

The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user:

Which task you want to do (choose an option between 1-2),

1- Entering new information

2- Searching a student If the user types something rather than 1-2, the program must print invalid response.

After completing one task, the program must ask the user if you want to do another task. If the user types yes, it should go to the beginning of the menu and asks which task you want to do? The program must continue to perform the tasks and asking the user if you want to perform a task as long as the user types yes if the user types No at the end of a task, the program must stop and prints a message:

Thank you and have a good day!

You should write your code as per the following instructions:

 If the user types 1 for entering new information:

 The program must ask the user how many students you have. (save it in a variable named num)

 You need to build one dimensional arrays with the size of num for names, last names, and student ids

 The program must take the student names, last names and student id, each one must be saved in an array.

 Choose appropriate data type for each array.

 If the user types 2 :  It must ask the following from the user:

 Type the student ID of the student you want?

 The student ID typed by the user must be saved in a variable named sd.

 The program must find the student that his ID matches with what the user types (sd).

 Print the information of that student including name, last name and grade?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Create a C# console application with the name StudentInfoAndGrade, add the below code in Program.cs

Program.cs

using System;

namespace StudentInfoAndGrade
{
    class Program
    {
        static void Main(string[] args)
        {
            //variable declarations
            bool doAgain = true;
            int userChoice;
            int num = -1;
            string[] firstNames = new string[0];
            string[] lastNames = new string[0];
            string[] studentIDs = new string[0];
            double[] grades = new double[0];
            string sd;
            string repeat;
            //repeat the process until the user enters no
            while (doAgain)
            {
                //display the menu options
                Console.WriteLine("Which task you want to do (choose an option between 1-2):");
                Console.WriteLine("1- Entering new information");
                Console.WriteLine("2- Searching a student");
                //read the user choice
                Console.Write("Enter your choice: ");
                userChoice = Convert.ToInt32(Console.ReadLine());
                //display error message if choice is invalid
                if (userChoice < 1 || userChoice > 2)
                    Console.WriteLine("Invalid response.");
                else
                {
                    //if user enters 1
                    if (userChoice == 1)
                    {
                        //prompt and read the number of students
                        Console.Write("\nHow many students you have? ");
                        num = Convert.ToInt32(Console.ReadLine());
                        //initialize the size of the arrays
                        firstNames = new string[num];
                        lastNames = new string[num];
                        studentIDs = new string[num];
                        grades = new double[num];
                        //run a loop to read the student information
                        for (int i = 0; i < num; i++)
                        {
                            Console.WriteLine("\nEnter details of student #" + (i + 1));
                            Console.Write("Enter firstname: ");
                            firstNames[i] = Console.ReadLine();
                            Console.Write("Enter lastname: ");
                            lastNames[i] = Console.ReadLine();
                            Console.Write("Enter ID: ");
                            studentIDs[i] = Console.ReadLine();
                            Console.Write("Enter grade: ");
                            grades[i] = Convert.ToDouble(Console.ReadLine());
                        }
                        Console.WriteLine();
                    }
                    //if the user enter 2
                    else
                    {
                        //num will be -1, if there are no student information entered
                        if (num == -1)
                        {
                            Console.WriteLine("Enter student information before search.");
                        }
                        else
                        {
                            //prompt and read the ID of the student to search
                            Console.Write("\nType the student ID of the student you want? ");
                            sd = Console.ReadLine();
                            int index = -1;
                            //run a loop and search the ID
                            for (int i = 0; i < num; i++)
                            {
                                if (studentIDs[i].ToLower() == sd.ToLower())
                                    index = i;
                            }
                            //if the index is -1 print student not found
                            if (index == -1)
                                Console.WriteLine("Student not found with the given ID.");
                            else
                            {
                                //display the student information if the ID is found
                                Console.WriteLine("\nFirst Name: " + firstNames[index]);
                                Console.WriteLine("Last Name: " + lastNames[index]);
                                Console.WriteLine("Grade: " + grades[index].ToString());
                            }
                        }
                    }
                    //prompt and read if the user wishes to perform another task
                    Console.Write("Do you want to do another task(yes/no)? ");
                    repeat = Console.ReadLine();
                    //continue if yes is entered
                    if (repeat.ToLower() == "yes")
                        doAgain = true;
                    //else terminate the loop
                    else
                    {
                        doAgain = false;
                        Console.WriteLine("\nThank you and have a good day!");
                    }
                }
            }
            Console.ReadKey();
        }
    }
}

Output:

Program Screenshot:

Let me know if you have any concerns with the above solution.

Add a comment
Know the answer?
Add Answer to:
C# Write a program that takes a list of information and grades of the students of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • Write a program that asks the user for a student name and asks for grades until...

    Write a program that asks the user for a student name and asks for grades until the user enters a non-number input, it should then ask if the user wants to enter another student, and keep doing the process until the user stops adding students. The student’s must be stored in a dictionary with their names as the keys and grades in a list. The program should then iterate over the dictionary elements producing the min, max, and mean of...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • (I would like this to be in five parts.) Write a program (Python module) that includes...

    (I would like this to be in five parts.) Write a program (Python module) that includes a function named studentrecords. This function must support execution of two loops. The first loop is to query the user whether they wish to enter additional records or not. It must accept responses of either yes or no as input, regardless of the letter-cases used for individual letters in the response. If the response is not recognized ( it isn’t yes or no) it...

  • Write a C++ program to keep records and perform statistical analysis for a class of 20...

    Write a C++ program to keep records and perform statistical analysis for a class of 20 students. The information of each student contains ID, Name, Sex, quizzes Scores (2 quizzes per semester), mid-term score, final score, and total score. The program will prompt the user to choose the operation of records from a menu as shown below: ==============================================                                            MENU =============================================== 1. Add student records 2. Delete student records 3. Update student records 4. View all student records 5. Calculate...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter...

    Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter the last name: Lee Hello Tom Lee. You are 21 years old. Press any key */   Declare an array named: firstName The array is a c_string, i.e., it is a null-terminated character array. The size of the array is 10. Assign a first name to it when it is declared.   Declare an array named: lastName The array is a c_string, The size of the...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT