C# RECORD
C# RECORD
using System;
class Student
{
public string name = "";
public int roll;
public int[] marks = new int[3];
public int[] ia = new int[3];
public int[] att = new int[3];
const int PASS_MARK = 40;
public void EnterDetails()
{
Console.Write("Enter Student Name: ");
name = Console.ReadLine();
do
{
Console.Write("Enter Internal Assessment (Out of 25): ");
ia[i] = int.Parse(Console.ReadLine());
if (ia[i] <= 0 || ia[i] > 25)
{
Console.WriteLine("Invalid input! IA marks should be between 1 and 25.");
}
} while (ia[i] <= 0 || ia[i] > 25);
do
{
Console.Write("Enter Attendance Percentage: ");
att[i] = int.Parse(Console.ReadLine());
if (att[i] < 0 || att[i] > 100)
{
Console.WriteLine("Invalid input! Attendance should be between 0 and 100.");
}
} while (att[i] < 0 || att[i] > 100);
if (ia[i] > 0 && att[i] >= 75)
{
do
{
Console.Write("Enter Marks (Out of 75): ");
marks[i] = int.Parse(Console.ReadLine());
if (marks[i] < 0 || marks[i] > 75)
{
Console.WriteLine("Invalid input! Marks should be between 0 and 75.");
}
} while (marks[i] < 0 || marks[i] > 75);
}
else
{
marks[i] = -1;
}
}
}
if (choice == 3)
{
Console.WriteLine("Exiting the Program");
break;
}
Subject 1:
Enter Internal Assessment (Out of 25): 24
Enter Attendance Percentage: 79
Enter Marks (Out of 75): 69
Subject 2:
Enter Internal Assessment (Out of 25): 19
Enter Attendance Percentage: 56
Subject 3:
Enter Internal Assessment (Out of 25): 22
Enter Attendance Percentage: 89
Enter Marks (Out of 75): 23
--------------------------------------------------------
Attendance Report for John (Roll No: 112)
--------------------------------------------------------
Subject 1: Attendance 79%, Status: Eligible for Exam
Subject 2: Attendance 56%, Status: Not Eligible for Exam
Subject 3: Attendance 89%, Status: Eligible for Exam
interface Inventory
{
void DisplayInfo();
}
class ItemDescription : Inventory // Base Class: Item Description
{
public int ItemID;
public string Name;
public double Price;
class Program
{
static void Main()
{
Sales[] stockItems = new Sales[10]; // Fixed-size array for 10 products
int productCount = 0;
while (true)
{
Console.WriteLine("\n====================================");
Console.WriteLine(" Inventory Control System ");
Console.WriteLine("====================================");
Console.WriteLine("1. Purchase Items (Add New Stock)");
Console.WriteLine("2. Sell Items");
Console.WriteLine("3. Display Stock");
Console.WriteLine("4. Exit");
Console.WriteLine("====================================");
Console.Write("Choose an option: ");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1: // Purchase Items
if (productCount >= stockItems.Length)
{
Console.WriteLine("\nInventory is full! Cannot add more products.\n");
break;
}
string? name;
do
{
Console.Write("Enter Name: ");
name = Console.ReadLine();
} while (string.IsNullOrWhiteSpace(name));
string? productName;
do
{
Console.Write("Enter Product Name: ");
productName = Console.ReadLine();
} while (string.IsNullOrWhiteSpace(productName));
if (!itemSold)
{
Console.WriteLine("\nProduct not found in stock!\n");
}
break;
case 3: // Display Stock
if (productCount == 0)
{
Console.WriteLine("\nNo stock available!\n");
break;
}
Console.WriteLine("\nCurrent Stock:");
for (int i = 0; i < productCount; i++)
{
stockItems[i].DisplayInfo();
Console.WriteLine($"Stock Quantity: {stockItems[i].Quantity}\n");
}
break;
case 4:
Console.WriteLine("\nExiting...\n");
return;
default:
Console.WriteLine("\nInvalid choice! Try again.\n");
break;
}
}
}
}
OUTPUT:
====================================
Inventory Control System
====================================
1. Purchase Items (Add New Stock)
2. Sell Items
3. Display Stock
4. Exit
====================================
Choose an option: 1
====================================
Inventory Control System
====================================
1. Purchase Items (Add New Stock)
2. Sell Items
3. Display Stock
4. Exit
====================================
Choose an option: 2
Enter Product Name: Salt
Enter Quantity to sell: 3
====================================
Product Sold Successfully!
====================================
Product: Salt
Quantity Sold: 3
Total Cost: $210.00
====================================
====================================
Inventory Control System
====================================
1. Purchase Items (Add New Stock)
2. Sell Items
3. Display Stock
4. Exit
====================================
Choose an option: 3
Current Stock:
====================================
ID: 101
Name: Salt
Price: $70.00
====================================
Stock Quantity: 7
====================================
Inventory Control System
====================================
1. Purchase Items (Add New Stock)
2. Sell Items
3. Display Stock
4. Exit
====================================
Choose an option: 4
Exiting...
PROGRAM 3:
using System;
namespace ArithmeticCalc
{
public class Calculator
{
private readonly double[] history = new double[10];
private int historyIndex;
while (true)
{
Console.WriteLine("\nSelect an option:");
Array.ForEach(menuOptions, Console.WriteLine);
if (choice == "6")
{
Console.WriteLine("Exiting...");
break;
}
if (choice == "5")
{
Console.WriteLine("Calculation History :");
int count = Math.Min(calc.history.Length, calc.historyIndex);
try
{
double result;
if (int.TryParse(input1, out int intNum1) && int.TryParse(input2, out int
intNum2))
{
result = choice switch
{
"1" => Add(intNum1, intNum2),
"2" => Subtract(intNum1, intNum2),
"3" => Multiply(intNum1, intNum2),
"4" => Divide(intNum1, intNum2),
_ => throw new Exception("Invalid choice.")
};
}
{
"1" => Add(doubleNum1, doubleNum2),
"2" => Subtract(doubleNum1, doubleNum2),
"3" => Multiply(doubleNum1, doubleNum2),
"4" => Divide(doubleNum1, doubleNum2),
_ => throw new Exception("Invalid choice.")
};
}
else
{
throw new Exception("Invalid input.");
}
Console.WriteLine($"Result: {result}");
calc.StoreResult(result);
}
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 1
Enter first number: 23
Enter second number: 56
Result: 79
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 2
Enter first number: 56
Enter second number: 78
Result: -22
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 3
Enter first number: 3
Enter second number: 71
Result: 213
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 4
Enter first number: 45
Enter second number: 3
Result: 15
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 5
Calculation History :
Result 1: 79
Result 2: -22
Result 3: 213
Result 4: 15
Select an option:
1. Add
2. Subtract
3. Multiply
4. Divide
5. View History
6. Exit
Your choice: 6
Exiting...
PROGRAM 4:
using System;
namespace AreaOfShapes
{
public abstract class Shape
{
public abstract double Area { get; }
if (choice == 4)
{
Console.WriteLine("Exiting program...");
break;
}
Shape shape = choice switch
{
1 => new Rectangle(),
2 => new Circle(),
3 => new Triangle(),
_ => throw new InvalidOperationException("Invalid shape selection.")
};
shape.GetDimensions();
Shape: Rectangle
Area: 1000.00
Length: 20
Width: 50
Shape: Circle
Area: 6361.73
Radius: 45
=== SHAPE AREA CALCULATOR ===
1. Rectangle
2. Circle
3. Triangle
4. Exit
Choose an option: 3
Enter base of the triangle: 20
Enter height of the triangle: 45
Shape: Triangle
Area: 450.00
Base: 20
Height: 45
namespace EmployeeLeaveApp
{
class Program
{
public delegate void LeaveDelegate(int empNo, string empName, DateTime fromDate,
DateTime toDate);
public delegate void DisplayDelegate(int empNo, string empName, DateTime fromDate,
DateTime toDate, string status, string reason, int totalDays);
class Student
{
public string name;
public int attendancePercentage;
Eligibility Check Failed: Attendance is only 45%. Not eligible to write the exam.
TestLock.balance = 50000;
Console.WriteLine("\n ==== Withdraw ==== ");
Console.ReadKey();
}
Withdraw:4000
Withdraw:7000
Withdraw:7000
Withdraw:3000
Withdraw:3000
Deposit:3000
Deposit:3000
Deposit:3000
Deposit:2000
Deposit:7000
namespace ComplexNumberAddition
{
class Complex
{
private double real;
private double imaginary;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first complex number:");
Console.Write("Real part: ");
double r1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Imaginary part: ");
double i1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nEnter the second complex number:");
Console.Write("Real part: ");
double r2 = Convert.ToDouble(Console.ReadLine());
Console.Write("Imaginary part: ");
double i2 = Convert.ToDouble(Console.ReadLine());
Real part: 4
Imaginary part: 5
Real part: 12
Imaginary part: 7
calc = --calc;
calc.Print();
Console.WriteLine();
calc1 = ++calc;
calc.Print();
Console.ReadKey();
}
}
}
OUTPUT:
Number1=13
Number2=-27
Number1=15
Number2=-25