C# Program Create a class student with a data member’s name and calculate marks and percentage.
Object:
C# Program Create a class student with a data member name, age, marks of English, marks of math, marks of science, total marks, obtained marks and percentage provide member functions CalculateTotalMarks and CalculatePercentage to calculate marks and percentage in main. C# Projects with Source Code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab_3a
{
class students
{
public void data()
{
string name;
int age;
double eng, math, sci, obt_marks, total_marks=300, per;
Console.WriteLine(“Enter Student Name: “);
name=Console.ReadLine();
Console.WriteLine(“Enter Student Age: “);
age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(“Enter Marks of English: “);
eng = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(“Enter Marks of Math: “);
math = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(“Enter Student Science: “);
sci = Convert.ToDouble(Console.ReadLine());
obt_marks = eng + math + sci;
per = (obt_marks / total_marks) * 100;
Console.WriteLine(“——————————————\n\n”);
Console.WriteLine(“Name of Student is: {0}”, name);
Console.WriteLine(“Student Age is : {0}”, age);
Console.WriteLine(“Obtained Marks : {0}”, obt_marks);
Console.WriteLine(“Percentage : {0}”, per);
}
}
class Program
{
static void Main()
{
students i = new students();
i.data();
Console.ReadKey();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lab_3a { class students { public void data() { string name; int age; double eng, math, sci, obt_marks, total_marks=300, per; Console.WriteLine("Enter Student Name: "); name=Console.ReadLine(); Console.WriteLine("Enter Student Age: "); age = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Marks of English: "); eng = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Enter Marks of Math: "); math = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Enter Student Science: "); sci = Convert.ToDouble(Console.ReadLine()); obt_marks = eng + math + sci; per = (obt_marks / total_marks) * 100; Console.WriteLine("------------------------------------------\n\n"); Console.WriteLine("Name of Student is: {0}", name); Console.WriteLine("Student Age is : {0}", age); Console.WriteLine("Obtained Marks : {0}", obt_marks); Console.WriteLine("Percentage : {0}", per); } } class Program { static void Main() { students i = new students(); i.data(); Console.ReadKey(); } } }
Output:
Another Program: C# Program Calculating the Area of a Rectangle
Another Program: C# Program that Subtracts two user-defined numbers
Pingback: Develop a C# app that will determine the gross pay for each of three employees
Pingback: Write a C# program that reads two arrays and checks whether they are equal.
Pingback: C# program to count vowels in a string
Pingback: Write a C# program to demonstrate the multiple inheritances
Pingback: Implement bubble sort in C# the value of array given by the users
Pingback: C# how to handle exceptions to illustrate try-catch action with Exceptions
Pingback: Top 20 C# programs examples in 2021