Answer to Question #188608 in C# for CHANDRASENA REDDY

Question #188608

Task 1: Create a library project and define a class called Participant. Define the private members and public properties as follows: EmpId, Name, Company Name, FoundationMarks, WebBasicMarks, DotNetMarks, Total Marks, ObtainedMarks, Percentage Initialise the Total Marks to 300. ObtainedMarks and Percentage are calculated fields.


Task 2: Add 3 constructors, one Default, one parameterised to initialize the members and one static constructor to initialise the company Name to “Corporate Unniversity”


Task 3: Add the following functions to the class: a. To calculate Total Marks. b. To calculate the percentage. c. To return the percentage


Task 4: Create a console application to accept the data about participants, and create the object. The console application should call the appropriate functions to calculate the Total Marks and Percentage. And then Display the percentage.



1
Expert's answer
2021-05-07T09:09:34-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace C_SHARP
{
    class Participant {
        //Task 1: Create a library project and define a class called Participant. 
        //Define the private members and public properties as follows: EmpId, Name, Company Name, 
        //FoundationMarks, WebBasicMarks, DotNetMarks, Total Marks, ObtainedMarks, Percentage Initialise
        //the Total Marks to 300. ObtainedMarks and Percentage are calculated fields.
        private int empId;


        public int EmpId
        {
            get { return empId; }
            set { empId = value; }
        }
        private string name;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private static string companyName;


        public static string CompanyName
        {
            get { return companyName; }
            set { companyName = value; }
        }
        private int foundationMarks;


        public int FoundationMarks
        {
            get { return foundationMarks; }
            set { foundationMarks = value; }
        }
        private int webBasicMarks;


        public int WebBasicMarks
        {
            get { return webBasicMarks; }
            set { webBasicMarks = value; }
        }
        private int dotNetMarks;


        public int DotNetMarks
        {
            get { return dotNetMarks; }
            set { dotNetMarks = value; }
        }
        //Initialise the Total Marks to 300.
        private const int totalMarks=300;


        public int TotalMarks
        {
            get { return totalMarks; }
        }
        private int obtainedMarks;


        public int ObtainedMarks
        {
            get { return obtainedMarks; }
            set { obtainedMarks = value; }
        }
        private double percentage;


        public double Percentage
        {
            get { return percentage; }
            set { percentage = value; }
        }
        //Task 2: Add 3 constructors, one Default, one parameterised to initialize the members 
        //and one static constructor to initialise the company Name to “Corporate Unniversity”
        public Participant() { }


        public Participant(int empId, string name, int foundationMarks, int webBasicMarks, int dotNetMarks) {
            this.empId = empId;
            this.name = name;
            this.foundationMarks = foundationMarks;
            this.webBasicMarks = webBasicMarks;
            this.dotNetMarks = dotNetMarks;
        }
        static Participant() {
            companyName = "Corporate Unniversity";
        }
        //Task 3: Add the following functions to the class: 
        //a. To calculate Total Marks.
        public void CalculateTotalMarks()
        {
            obtainedMarks += foundationMarks + webBasicMarks + dotNetMarks;
        }
        //b. To calculate the percentage. 
        public void CalculatePercentage()
        {
            percentage = ((double)obtainedMarks / (double)totalMarks)*100.0;
        }
        //c. To return the percentage
        public double getPercentage()
        {
            return percentage;
        }


    }




    class Program
    {
        


        static void Main(string[] args)
        {
            //Task 4: Create a console application to accept the data about participants, and create the object. 
            Participant participant = new Participant();
            Console.Write("Enter emp Id: ");
            participant.EmpId = int.Parse(Console.ReadLine());
            Console.Write("Enter name: ");
            participant.Name = Console.ReadLine();
            Console.Write("Enter foundation marks: ");
            participant.FoundationMarks = int.Parse(Console.ReadLine());
            Console.Write("Enter web basic marks: ");
            participant.WebBasicMarks  = int.Parse(Console.ReadLine());
            Console.Write("Enter dot net marks: ");
            participant.DotNetMarks = int.Parse(Console.ReadLine());   
            //The console application should call the appropriate functions to calculate the Total Marks and Percentage. 
            participant.CalculateTotalMarks();
            participant.CalculatePercentage();
            Console.WriteLine("\nCompany Name: {0}", Participant.CompanyName);
            Console.WriteLine("Total Marks: {0}", participant.ObtainedMarks);
            //And then Display the percentage.
            Console.WriteLine("Percentage: {0} %", participant.getPercentage().ToString("N"));
            


            
            Console.ReadKey();
        }


    }
}



Ouput:


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