Answer to Question #213848 in C# for Hassam

Question #213848

You are required to code for “Students attendance” system to keep record of attendance of complete semester.    

Write a class AttendaceRecord having properties section, regNumber, studentName, AttendanceStatus (a char either P or A) and a function to mark attendance. Also create a List of type AttendanceRecord and call the required function/s to mark attendance when required. The system should be able to perform the following functions:

·        View attendance record of given student to show Student name, Registration number, percentage of total presents/absents and total attendance record (so far)

·        Calculate Short attendance to display all those students whose attendance is below the given threshold value (given in percentage).



1
Expert's answer
2021-07-05T13:28:46-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q213848
{
    class AttendanceRecord
    {
        //Write a class AttendaceRecord having 
        //properties section, regNumber, studentName, AttendanceStatus (a char either P or A) and a function to mark attendance. 
        public string Section { get; set; }
        public string RegNumber { get; set; }
        public string StudentName { get; set; }
        public List<char> AttendanceStatus = new List<char>();


        public void markAttendance(char attendanceStatus)
        {
            this.AttendanceStatus.Add(attendanceStatus);
        }




        public double calculatePercentageTotalPresents()
        {
            int totalPresents = 0;
            for (int i = 0; i < AttendanceStatus.Count; i++)
            {
                if (AttendanceStatus[i].ToString().ToLower() == "p")
                {
                    totalPresents++;
                }
            }
            return ((double)totalPresents / (double)AttendanceStatus.Count)*100.0;
        }


    }
    class Program
    {
        //The system should be able to perform the following functions:
        //View attendance record of given student to show Student name, Registration number, percentage of total presents/absents and total attendance record (so far)
        static void viewAttendanceRecord(AttendanceRecord attendanceRecord)
        {
            Console.WriteLine("Section: {0}", attendanceRecord.Section);
            Console.WriteLine("Reg. Number: {0}", attendanceRecord.RegNumber);
            Console.WriteLine("Student Name: {0}", attendanceRecord.StudentName);
            Console.WriteLine("Attendance Status: {0}", attendanceRecord.AttendanceStatus);


            double percentageTotalPresents = attendanceRecord.calculatePercentageTotalPresents();
            double percentageTotalAbsents = 100.0 - percentageTotalPresents;
            Console.WriteLine("\nTotal attendance record: {0}", attendanceRecord.AttendanceStatus.Count);
            Console.WriteLine("Percentage of total presents: {0}", percentageTotalPresents);
            Console.WriteLine("Percentage of total absents: {0}", percentageTotalAbsents);
        }
        //Calculate Short attendance to display all those students whose attendance is below the given threshold value (given in percentage).
        static void calculateShortAttendance(List<AttendanceRecord> attendanceRecords, double percentage)
        {
            for (int i = 0; i < attendanceRecords.Count; i++)
            {
                if (attendanceRecords[i].calculatePercentageTotalPresents() < percentage)
                {
                    viewAttendanceRecord(attendanceRecords[i]);
                }
            }
        }


        static void Main(string[] args)
        {
            //Also create a List of type AttendanceRecord and call the required function/s to mark attendance when required. 
            List<AttendanceRecord> attendanceRecords = new List<AttendanceRecord>();


            Console.Write("Enter number of students: ");
            int number;
            int.TryParse(Console.ReadLine(), out number);
            int totalAttendance;
            Console.Write("Enter number of attendance: ");
            int.TryParse(Console.ReadLine(), out totalAttendance);


            for (int i = 0; i < number; i++)
            {
                AttendanceRecord attendanceRecord = new AttendanceRecord();
                Console.Write("Enter Section: ");
                attendanceRecord.Section = Console.ReadLine();
                Console.Write("Enter Reg. Number: ");
                attendanceRecord.RegNumber = Console.ReadLine();
                Console.Write("Enter Student Name: ");
                attendanceRecord.StudentName = Console.ReadLine();
                for (int a = 0; a < totalAttendance; a++)
                {
                    Console.Write("Enter Attendance Status (P - present/ A - absent): ");
                    attendanceRecord.markAttendance(Console.ReadLine()[0]);
                }


                attendanceRecords.Add(attendanceRecord);
            }
            for (int i = 0; i < number; i++)
            {
                viewAttendanceRecord(attendanceRecords[i]);
            }
            Console.Write("\nEnter percentage: ");
            double percentage;
            double.TryParse(Console.ReadLine(), out percentage);
            calculateShortAttendance(attendanceRecords, percentage);
            Console.ReadLine();
        }


    }
}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS