C# Program to Computes the Marks of Student in 6 Subjects and Displays the Total Marks and Average Marks of the Student

It is a simple c# program to calculate the result of student in different subjects. The program takes obtained marks from 6 different courses and displays their total marks and average marks of the class.

Source Code   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarksCalculator
{
    class Program
    {
        struct student
        {
            public string name;
            public string[] grade;
        };

        //Struct Instance
        student[] stdInstance = new student[50];


        //Class variables
        int size = 0;
        
        static void Main(string[] args)
        {
            Program m = new Program();
            m.size = 0;
            String exit_choice;
            do
            {
                Console.Write("\a\n\n\n"
                + "\t*******************************************************" + "\n"
                + "\t**                                                   **" + "\n"
                + "\t**                   Welcome                         **" + "\n"
                + "\t**                                                   **" + "\n"
                + "\t*******************************************************" + "\n");
                Console.Write("\t\t\t");
                student_menu(m);
                Console.Write("\n"
                + "\a\t  Do you want to continue ( y / n)");
                exit_choice = Console.ReadLine();
            } while (exit_choice == "y" || exit_choice == "Y");
        }

        private static void student_menu(Program m)
        {

            int student_menu_choice;
            Console.Write("\n"
            + "\a\t  *******************************************************" + "\n"
            + "\t  **                                                   **" + "\n"
            + "\t  **                   You Are In                      **" + "\n"
            + "\t  **                                                   **" + "\n"
            + "\t  **                   Student Menu                    **" + "\n"
            + "\t  **                                                   **" + "\n"
            + "\t  *******************************************************" + "\n"
            + "\n");

            Console.Write("\t\t  What do you want to do for student  " + "\n"
            + "\t\t  ===================================" + "\n"
            + "\n"
            + "\n\n\t 1  =>  Add student  "
            + "\n\n\t 2  =>  Student menu Exit \n"
            + "\t===     ------------------ " + "\n"
            + "\t\t\t\tYou Select : ");

            student_menu_choice = Convert.ToInt32(Console.ReadLine());

            if (student_menu_choice > 0)
            {
                switch (student_menu_choice)
                {
                    case 1:
                        {
                            add_student(m);//Function
                            break;
                        }
                    case 2:
                        {
                            return;
                        }
                    default:
                        {
                            return;
                        }
                }//end switch
            }//end if
            else
            {
                Console.Clear();

            }//end else
            return;
        }

        private static void add_student(Program m)
        {
            Console.Clear();
            Console.Write("\n" + "\n" + "\n"
            + "\n" + "\n" + "\n"
            + "\a\t  *******************************************************" + "\n"
            + "\t  **                                                   **" + "\n"
            + "\t  **                  Adding Student                   **" + "\n"
            + "\t  **                                                   **" + "\n"
            + "\t  *******************************************************" + "\n");

           
            Console.Write("\n"
            + "\t\tCOLLECTING DATA FOR STUDENT NO : " + m.size
            + "\n"
            + "\n\tEnter name  : ");

            
            m.stdInstance[m.size].name = Console.ReadLine();//taking name
            m.stdInstance[m.size].grade = new String[6];
            for (int i = 0; i < 6; i++)
            {
                Console.Write("\n\tEnter Score For course # " + (i + 1) + " : ");
                m.stdInstance[m.size].grade[i] = Console.ReadLine();

            }

            Console.Write("\n"
            + "Student added with following data" + "\n"
            + "\n"
            + "Name : " + m.stdInstance[m.size].name + "\n");
            int sum = 0, average = 0;

            for (int j = 0; j < 6; j++)
            {
                Console.Write("\n\tScore For course # " + j + 1 + " : " + m.stdInstance[m.size].grade[j]);
                if (Convert.ToInt32(m.stdInstance[m.size].grade[j]) < 50)
                {
                    Console.Write("\n\tGrade is : F ");
                }
                else
                {
                    Console.Write("\n\tGrade is : Not F ");
                }
                sum = sum + Convert.ToInt32(m.stdInstance[m.size].grade[j]);
            }
            Console.Write("\n\n\tSum For courses : " + sum);
            average = sum / 6;
            Console.Write("\n\n\tAverage For courses : " + average);
            if (average < 50)
            {
                Console.Write("\n\n\tNot Promoted ");
            }
            else
            {
                Console.Write("\n\n\tPromoted");
            }
            m.size++;
        }
    }
}

Output of the Program

C# Program to calculate the marks of different student in the class

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment