VISUAL PROGRAMING
Assignment # 1
Cs-412 visual programing
Submitted By:
Muhammad Saqib
Registration Number:
2024-ag-7977
Submitted To:
Mr. Haris Pervaiz
Department of Computer Science
University of Agriculture Faisalabad Sub-Campus Depalpur Okara
[Link]
using System;
using [Link];
class flrogram
{
static List<Student> students = new List<Student>();
static void Main()
{
while (true)
{
[Link]("\n===== STUDE T MA AGEME T SYSTEM =====");
[Link]("1. Add Student");
[Link]("2. View All Students");
[Link]("3. Search Student (ID/ ame)");
[Link]("4. Update Student Marks");
[Link]("5. Delete Student");
[Link]("6. Exit");
int choice = ReadInt("Enter choice: ");
switch (choice)
{
case 1: AddStudent(); break;
case 2: ViewStudents(); break;
case 3: SearchStudent(); break;
case 4: UpdateStudent(); break;
case 5: DeleteStudent(); break;
case 6:
[Link]("flrogram Ended.");
return;
default:
[Link]("Invalid choice!");
break;
}
}
}
// ADD STUDE T
static void AddStudent()
{
int id = ReadInt("Enter ID: ");
string name = ReadString("Enter ame: ");
int age = ReadInt("Enter Age: ");
string dept = GetDepartment();
int[] marks = ReadMarks();
Student s = new Student(id, name, age, dept, marks);
[Link](s);
[Link]("✅ Student Added Successfully!");
}
// VIEW ALL
static void ViewStudents()
{
if ([Link] == 0)
{
[Link](" o records found.");
return;
}
foreach (var s in students)
{
[Link]();
}
}
// SEARC
static void SearchStudent()
{
[Link]("Search by ID or ame: ");
string input = [Link]();
bool found = false;
foreach (var s in students)
{
if ([Link]() == input || s. [Link]() == [Link]())
{
[Link]();
found = true;
}
}
if (!found)
[Link]("❌ Student not found.");
}
// UflDATE
static void UpdateStudent()
{
int id = ReadInt("Enter ID to update: ");
foreach (var s in students)
{
if ([Link] == id)
{
[Link]("Enter new marks:");
int[] newMarks = ReadMarks();
[Link](newMarks);
[Link]("✅ Marks updated!");
return;
}
}
[Link]("❌ Student not found.");
}
// DELETE
static void DeleteStudent()
{
int id = ReadInt("Enter ID to delete: ");
for (int i = 0; i < [Link]; i++)
{
if (students[i].Id == id)
{
[Link](i);
[Link](" Student deleted!");
return;
}
}
[Link]("❌ Student not found.");
}
// I flUT MET ODS
static int ReadInt(string msg)
{
int val;
while (true)
{
[Link](msg);
if ([Link]([Link](), out val))
return val;
[Link]("Invalid number!");
}
}
static string ReadString(string msg)
{
string input;
do
{
[Link](msg);
input = [Link]();
if ([Link] ullOrWhiteSpace(input))
[Link]("Cannot be empty!");
} while ([Link] ullOrWhiteSpace(input));
return input;
}
static int[] ReadMarks()
{
int[] marks = new int[3];
for (int i = 0; i < 3; i++)
{
while (true)
{
marks[i] = ReadInt($"Enter marks for subject {i + 1}: ");
if (marks[i] >= 0 fifi marks[i] <= 100)
break;
[Link]("Marks must be between 0 and 100.");
}
}
return marks;
}
static string GetDepartment()
{
while (true)
{
[Link]("1. CS\n2. IT\n3. SE");
int choice = ReadInt("Select Department: ");
switch (choice)
{
case 1: return "CS";
case 2: return "IT";
case 3: return "SE";
default:
[Link]("Invalid choice!");
break;
}
}
}
}
[Link]
using System;
public class Student
{
public int Id { get; set; }
public string ame { get; set; }
public int Age { get; set; }
public string Department { get; set; }
public int[] Marks { get; set; }
public int Total { get; private set; }
public double Average { get; private set; }
public string Grade { get; private set; }
public bool Isflassed { get; private set; }
public Student(int id, string name, int age, string department, int[] marks)
{
Id = id;
ame = name;
Age = age;
Department = department;
Marks = marks;
CalculateResults();
}
public void CalculateResults()
{
CalculateTotal();
CalculateAverage();
CalculateGrade();
Checkflass();
}
private void CalculateTotal()
{
Total = 0;
foreach (int mark in Marks)
{
Total += mark;
}
}
private void CalculateAverage()
{
Average = (double)Total / [Link];
}
private void CalculateGrade()
{
if (Average >= 80)
Grade = "A";
else if (Average >= 60)
Grade = "B";
else if (Average >= 40)
Grade = "C";
else
Grade = "F";
}
private void Checkflass()
{
Isflassed = Average >= 40;
}
public void UpdateMarks(int[] newMarks)
{
Marks = newMarks;
CalculateResults();
}
public void Display()
{
[Link]("\n==============================");
[Link]($"ID : {Id}");
[Link]($" ame : { ame}");
[Link]($"Age : {Age}");
[Link]($"Department : {Department}");
[Link]($"Marks : {Marks[0]}, {Marks[1]}, {Marks[2]}");
[Link]($"Total : {Total}");
[Link]($"Average : {Average:F2}");
[Link]($"Grade : {Grade}");
[Link]($"Status : {(Isflassed o "flASS" : "FAIL")}");
[Link]("==============================");
}
}
OUTPUT