How do I make my code output information about the students in the C# assignment:

Joined
Nov 28, 2024
Messages
1
Reaction score
0
C#:
using System;

namespace krasinqmashemi6ka_19112024
{
    class Program
    {
        static void Main(string[] args)
        {

            Zaglavie();
            Izberi();
            

        }
        static void Zaglavie()
        {
            Console.WriteLine("Powered by DJ KrassiBoy");
            Console.WriteLine("Welcome to the student management program of 11th A GRADE");
            Console.WriteLine("Loading....");
            Console.WriteLine("Loading...");
        }
        static void Izberi()
        {
            Console.Write("How Many students will have in that class? ");
            int kolko = int.Parse(Console.ReadLine());
            Console.WriteLine("OK, " + kolko + " student/s ");
            string[] name = new string[kolko];
           // int i = 0;
            while (true)
            {
                Console.WriteLine("Choose one of the options");
                Console.WriteLine("1 - To Enter a student");
                Console.WriteLine("2 - To Delete Students");
                Console.WriteLine("3 - To Show All Students in List");
                Console.WriteLine("4 - To search a student");
                Console.WriteLine("5 - To Exit");
                Console.Write("Insert an option number (1-5): ");

                int choosenum = int.Parse(Console.ReadLine());

                if (choosenum == 1)
                {
                    Dobavi(kolko);
                }
                else if (choosenum == 2)
                {
                    Iztrii();
                }
                else if (choosenum == 3)
                {
                    Showallstudents(name,kolko);
                }
                else if (choosenum == 4)
                {
                    Searchastudent();
                }
                else if (choosenum == 5)
                {
                    Exit();
                    break;
                }
            }
            
        }
        static public void Dobavi(int kolko)
        {
            Console.WriteLine("You have entered the option to add a student.");
            string[] name = new string[kolko];
            for (int i = 0; i < kolko; i++)
            {
                Console.Write("Insert a name: ");
                name[i] = Console.ReadLine();
            }
        }
        static void Iztrii()
        {
            Console.WriteLine("You have entered the option to delete a student.");
        }
        static void Showallstudents(string [] name, int kolko)
        {
            Console.WriteLine("You have entered the option to show all of the students.");
            Console.WriteLine("Loading Database....");
            Console.WriteLine("Loading Database...");
            for (int i = 0; i < name.Length; i++)
            {
                Console.WriteLine("Showing Student " + i + " info: " + name[i]);
            }

        }
        static void Searchastudent()
        {
            Console.WriteLine("You have entered the option to search between all of the students.");
            int number;

        }
        static void Exit()
        {
            Console.WriteLine("Bye! Do not forget to send greetings to the DJ and Junior Tours!");
          
        }
        /*static void uchenici(string[]name, int a)
        {

            for (int i = 0; i<name.Length; i++)
            {
                name[i] = Console.ReadLine();
            }
            
        }*/
    }
}
Can you give me some ideas for that code? I've tried lots of methods but...with no luck. Some Suggestions? I've tried all. Give me some ideas
1732788010261.png
 
Joined
Jul 4, 2023
Messages
507
Reaction score
63
This simple change to your code might serve as inspiration for you in solving your problem. ;)
[ working code on-line ]
C#:
using System;
using System.Collections.Generic;
using System.Threading;

class Program
{
    static string newLine = Environment.NewLine;
    //                                                           name    surname
    static List<Tuple<string, string>> students = new List<Tuple<string, string>>();
 
    static void Main(string[] args)
    {
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        PoweredBy();
        FakeLoader();
        Menu();

        Environment.Exit(0);
    }

    static void Menu()
    {
        ShowMenuOptions();

        while (true)
        {     
            Console.Write("\rInsert an option number (1-5): ");

            ConsoleKeyInfo keyInfo = Console.ReadKey();
            char keyChar = keyInfo.KeyChar;

            if (char.IsDigit(keyChar))
            {
                int input = int.Parse(keyChar.ToString());
                if (input >= 1 && input <= 6)
                {
                    switch (input)
                    {
                        case 1:
                            Menu__AddStudent();
                            break;
                        case 2:
                            Menu__DeleteStudent();
                            break;
                        case 3:
                            Menu__ShowAllStudents();
                            break;
                        case 4:
                            Menu__SearchStudent();
                            break;
                        case 5:
                            Menu__CreateDemoList();
                            break;
                        case 6:
                            Menu__Exit();
                            return;
                    }
                }
            }
        }
    }

    static void Menu__AddStudent()
    {
        PoweredBy();

        Console.Write("Enter student's first name: ");
        string name = Console.ReadLine().Trim();
  
        Console.Write("Enter student's surname: ");
        string surname = Console.ReadLine().Trim();

        if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(surname))
        {
            name = CapitalizeFirstLetter(name);
            surname = CapitalizeFirstLetter(surname);
            students.Add(Tuple.Create(name, surname));
            Console.Write("Student " + name + " " + surname + " has been added.");
        }
        else
        {
            Console.Write("Student has not been added due to missing information.");
        }
  
        Thread.Sleep(2500);
        ShowMenuOptions();
    }

    static void Menu__DeleteStudent()
    {
        PoweredBy();

        if (students.Count != 0)
        {
            Console.Write("Enter student's name to delete: ");
            string name = Console.ReadLine().Trim();

            Console.Write("Enter student's surname to delete: ");
            string surname = Console.ReadLine().Trim();

            name = CapitalizeFirstLetter(name);
            surname = CapitalizeFirstLetter(surname);

            var studentToDelete = students.Find(student => student.Item1 == name && student.Item2 == surname);

            if (studentToDelete != null)
            {
                students.Remove(studentToDelete);
                Console.Write("Student " + name + " " + surname + " has been deleted.");
            }
            else
            {
                Console.Write("Student not found.");
            }
        }
        else
        {
            ErrorText("No students on the list. You cannot delete a student.");
        }

        Thread.Sleep(2500);
        ShowMenuOptions();
    }

    static void Menu__ShowAllStudents()
    {
        PoweredBy();

        if (students.Count != 0)
        {
            TitleLine("List of all students:");
            int index = 1;
            foreach (var student in students)
            {
                Console.WriteLine(index++ + ". " + student.Item1 + " " + student.Item2);
            }

            Console.Write(newLine + "Press spacebar button to exit to main menu.");
            Console.ReadKey();
        }
        else
        {
            ErrorText("No students on the list. Cannot show all students.");
            Thread.Sleep(2500);
        } 
  
        ShowMenuOptions();
    }

    static void Menu__SearchStudent()
    {
        PoweredBy();

        if (students.Count != 0)
        {
            Console.Write("Enter student's name to search: ");
            string name = Console.ReadLine().Trim();

            Console.Write("Enter student's surname to search: ");
            string surname = Console.ReadLine().Trim();

            name = CapitalizeFirstLetter(name);
            surname = CapitalizeFirstLetter(surname);

            var studentFound = students.Find(student => student.Item1 == name && student.Item2 == surname);

            if (studentFound != null)
            {
                Console.Write("Student found: " + studentFound.Item1 + " " + studentFound.Item2);
            }
            else
            {
                Console.Write("Student not found.");
            }
        }
        else
        {
            ErrorText("No students on the list. You cannot search for a student.");
        }

        Thread.Sleep(2500);
        ShowMenuOptions();
    }

    static void Menu__CreateDemoList()
    {
        PoweredBy();

        List<Tuple<string, string>> demoStudents = new List<Tuple<string, string>>()
        {
            Tuple.Create("Ivan", "Ivanov"),
            Tuple.Create("Maria", "Petrova"),
            Tuple.Create("Alexei", "Sidorov"),
            Tuple.Create("Anna", "Kuznetsova"),
            Tuple.Create("Dmitry", "Popov"),
            Tuple.Create("Olga", "Volkova"),
            Tuple.Create("Sergey", "Mikhailov"),
            Tuple.Create("Ekaterina", "Fedorova"),
            Tuple.Create("Andrei", "Nikolaev"),
            Tuple.Create("Yulia", "Smirnova")
        };

        students.AddRange(demoStudents);

        Console.Write("Demo list of students has been created.");

        Thread.Sleep(2500);
        ShowMenuOptions();
    }


    static void Menu__Exit()
    {
        PoweredBy();

        Console.Write("Bye! Do not forget to send greetings to the DJ and Junior Tours!");
        Thread.Sleep(2500);
    }

    static void ShowMenuOptions()
    {
        PoweredBy();
        TitleLine("Choose one of the options");
        Console.WriteLine
        (
            "1 - To Enter a student" + newLine
            + "2 - To Delete Student" + newLine
            + "3 - To Show All Students" + newLine
            + "4 - To Search a Student" + newLine
            + "5 - Create Demo list of students" + newLine
            + "6 - To Exit" + newLine
        );
    }

    static string CapitalizeFirstLetter(string text)
    {
        if (!String.IsNullOrEmpty(text))
            return char.ToUpper(text[0]) + text.Substring(1).ToLower();
        return text;
    }

    static void ErrorText(string text)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(text);
        Console.ForegroundColor = ConsoleColor.White;
    }

    static void TitleLine(string text)
    {
        Console.BackgroundColor = ConsoleColor.White;
        Console.ForegroundColor = ConsoleColor.Black;
        Console.WriteLine(" " + text + " ");
        Console.BackgroundColor = ConsoleColor.Black;
        Console.ForegroundColor = ConsoleColor.White;
    }

    static void PoweredBy()
    {
        string coder = "Powered by DJ KrassiBoy";
        string welcome = "Welcome to the student management program of 11th A GRADE";
        string border = new string('*', welcome.Length + 4);

        Console.Clear();
        Console.WriteLine
        (
            border + newLine
            + "* " + coder.PadRight(border.Length - 3) + "*" + newLine
            + "* " + welcome.PadRight(border.Length - 3) + "*" + newLine
            + border + newLine
        );
    }

    static void FakeLoader(string text = "Loading")
    {
        string loadingText = text;
        int dotCount = 3; // Number of dots in the animation
        Random random = new Random(); // Random number generator
        int cycles = random.Next(3, 6); // Random number of animation cycles between 3 and 6
        string clearLine = new string(' ', loadingText.Length + dotCount); // Clear line for erasing content

        for (int j = 0; j < cycles; j++) // Loop for the number of animation cycles
        {
            for (int i = 0; i <= dotCount; i++) // Loop through each animation step
            {
                Console.Write("\r" + clearLine); // Clear the current line
                Console.Write("\r" + loadingText + new string('.', i)); // Display the loading text with dots
                Thread.Sleep(500); // Wait for the next frame - delay between frames in milliseconds
            }
        }

        Console.Write("\r" + clearLine + "\n");
    }
}
1732935015710.png
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,440
Members
47,101
Latest member
DoloresHol

Latest Threads

Top