0% found this document useful (0 votes)
54 views7 pages

Zain Rizvi 02-134162-140 Lab 12

The document describes a menu driven program for managing employee records. It includes the following: 1) The program allows the user to add, display, search, and delete employee records stored in an array. 2) The main menu is displayed with options to perform these actions, and the user enters a selection which calls the corresponding method. 3) Methods are defined to implement each action - add collects input and stores it in the array, display outputs all records, search checks for a matching name, and delete sets the matching record to null.

Uploaded by

Zain Rizvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

Zain Rizvi 02-134162-140 Lab 12

The document describes a menu driven program for managing employee records. It includes the following: 1) The program allows the user to add, display, search, and delete employee records stored in an array. 2) The main menu is displayed with options to perform these actions, and the user enters a selection which calls the corresponding method. 3) Methods are defined to implement each action - add collects input and stores it in the array, display outputs all records, search checks for a matching name, and delete sets the matching record to null.

Uploaded by

Zain Rizvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

[Lab no.

13] [Computer Programming]


[Menu Driven Approach]
Task No. 1: Design a program of Employee in which you have to take information of 05
employees. Information includes (employee_id, name, date of birth, email, residential
address, job title, salary…etc.) and save all the records in a txt file using StreamWriter

Solution:
using System;
using System.Collections.Generic;
using System.Text;

namespace lab13
{
class cal
{
public void calsu()
{
menu();
}
public static void menu(){
Console.WriteLine("***************************");
Console.WriteLine(" Calculator");
Console.WriteLine("***************************");
Console.WriteLine("Enter num1:");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter num2:");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("***************************");
Console.WriteLine("Press 1 for Add");
Console.WriteLine("Press 2 for sub");
Console.WriteLine("Press 3 for multiply");
Console.WriteLine("Press 4 for divide");
Console.WriteLine("Press 5 for exit");

switch (Convert.ToInt32(Console.ReadLine()))
{
case 1:
{
Console.WriteLine("***************************");

add(num1, num2);
break;
}
case 2:
{

Console.WriteLine("***************************");
sub(num1, num2);
break; }
case 3:
{
Console.WriteLine("***************************");
mul(num1, num2);
break;}
case 4:
{
/ Console.WriteLine("***************************");
div(num1, num2);
break;
}
[Lab no.13] [Computer Programming]
[Menu Driven Approach]
case 5:
{
Environment.Exit(0);
break;
}
}
}
public static void div(int num1, int num2)
{
Console.WriteLine(num1 + "/" + num2 + "=" + (num1 / num2));
}
public static void mul(int num1, int num2)
{
Console.WriteLine(num1 + "x" + num2 + "=" + (num1 * num2));
menu();
}
public static void sub(int num1, int num2)
{
Console.WriteLine(num1 + "-" + num2 + "=" + (num1 - num2));
menu();
}
public static void add(int num1, int num2)
{
Console.WriteLine(num1 + "+" + num2 + "=" + (num1 + num2));
menu();
}
}
}

Output:
[Lab no.13] [Computer Programming]
[Menu Driven Approach]
Task No. 2: Create a simple application which will add employee, delete employee and
search employee in array of profile.

Solution: using System;


class Emp {
struct employee
{
public string eName;
public string age;
public string designation;
public string salary;
}
public void min()
{
Console.Write("\n\nEmployee Management System :\n");
Console.Write("-------------------------------------------------------\n");
Console.Write("Enter Array size:");
int total = Convert.ToInt32(Console.ReadLine());
employee[] emp = new employee[total];

// add(emp, total);
// display(emp, total);

Menuss(emp, total);
}
private static void Menuss(employee[] emp, int total)
{

Console.WriteLine("******************************************************");
Console.WriteLine("*********************MAIN MENU************************");
Console.WriteLine("******************************************************");

Console.WriteLine("Press 1 to Add new emp");


Console.WriteLine("Press 2 to display");
Console.WriteLine("Press 3 to search");
Console.WriteLine("Press 4 to delete");

switch (Convert.ToInt32(Console.ReadLine()))
{

case 1:
{
add(emp, total);
break;
}
case 2:
{
display(emp, total);
break;
}
case 3:
{
search(emp, total);
break;
}

case 4:
[Lab no.13] [Computer Programming]
[Menu Driven Approach]
{
delete(emp, total);
break;
}
}

}
private static void search(employee[] emp, int total)
{
Console.Write("Enter Name to search");
string name = Console.ReadLine();
for (int i = 0; i < total; i++)
{
if (emp[i].eName == name)
{
Console.WriteLine(emp[i].eName + " " + emp[i].age + " " + emp[i].designation + " " +
emp[i].salary);

}
}

}
private static void add(employee[] emp, int total)
{
for (int i = 0; i < total; i++)
{
Console.Write("Name of the employee : ");
string nm = Console.ReadLine();
emp[i].eName = nm;

Console.Write("Employee Age: ");


string age = Console.ReadLine();
emp[i].age = age;

Console.Write("Job-Designation : ");
string desig = Console.ReadLine();
emp[i].designation = desig;

Console.Write("Enter Salary ");


string sal = Console.ReadLine();
Console.WriteLine();
emp[i].salary = sal;
}
Menuss(emp, total);
}
private static void display(employee[] emp, int total)
{
for (int i = 0; i < total; i++)
{
Console.WriteLine(emp[i].eName + " " + emp[i].age + " " + emp[i].designation + " " +
emp[i].salary);
}
Menuss(emp, total);
}
private static void delete(employee[] emp, int total)
{
Console.Write("Enter Name to search");
string name = Console.ReadLine();
for (int i = 0; i < total; i++)
{
if (emp[i].eName == name)
[Lab no.13] [Computer Programming]
[Menu Driven Approach]
{
emp[i].eName = null;
emp[i].age = null;
emp[i].designation = null;
emp[i].salary = null;
}
}
Menuss(emp, total);
}
}

Output:
Add employee

Search
[Lab no.13] [Computer Programming]
[Menu Driven Approach]

Display:

Deleted

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy