Answer to Question #318241 in C# for Madhu

Question #318241

Calculate overall percentage obtained by cadet in different assessments and generate score card.


The program should collect assessment details for cadet and calculate percentage score obtained by cadet for all the assessments .The details collectedand calculated should be used to generate score card.


The exercise contains a class named program with the below given methods.


GetOverallScore() : int

- should take set of assessment cards as parameter.

- Retrieve the maximum score for each assessment type. Assessment type should be an enumeration.

- should return percentage score value as integer for the average calculated.


GenerateScoreCard() : string


AssessmentType : enum


Maximum scores for these assessment types are:

Quiz -50

KBA - 100

Calibration -150

Hackathon -200

- the maximum score must be obtained from the enum values itself


AssessmentCard : struct





1
Expert's answer
2022-03-26T02:39:17-0400
using System;
using System.Collections.Generic;


namespace OneDollarTask
{
    enum AssessmentType
    {
        Quiz = 50,
        KBA = 100,
        Calibration = 150,
        Hackathon = 200
    }
    struct AssessmentCard
    {
        public Dictionary<AssessmentType, double> Assessments;
        public AssessmentCard(Dictionary<AssessmentType, double> assessments)
        {
            Assessments = assessments;
        }
    }


    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GenerateScoreCard());


            Console.ReadKey();
        }
        public static int GetOverallScore(Dictionary<AssessmentType, double> assessments)
        {
            double sum = 0;
            foreach (var item in assessments)
            {
                double maxAssessment = (int)item.Key;
                sum += item.Value / maxAssessment * 100;
            }


            return (int)(sum/assessments.Count);
        }
        public static string GenerateScoreCard()
        {
            AssessmentCard card = new AssessmentCard(new Dictionary<AssessmentType, double>() {
                {AssessmentType.Quiz,20 },
                {AssessmentType.KBA, 70 },
                {AssessmentType.Calibration, 130 },
                {AssessmentType.Hackathon, 150 } });
 


            return $"Overall score: {GetOverallScore(card.Assessments)}%";
        }
    }
}

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