Zain Rizvi 02-134162-140 Lab 12
Zain Rizvi 02-134162-140 Lab 12
Karachi Campus
Submitted By:
____Zain Rizvi________________________46064_______
(Name) (Reg. No.)
Submitted To:
7 8/Nov/2020 7 LOOP
9 04/12/2020 9 Arrays
10 12/12/2020 10 2D Array
11 27/12/2020 11 Methods
12 4/1/2021 12 Fiing
SNO DATE LAB LAB OBJECTIVE SIGN
NO
Bahria University,
Karachi Campus
Submitted On:
4/ Jan /2021
(Date: DDMM/YY)
[Lab no.12] [Computer Programming]
[Filing]
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:
class emp
{
static public void adduser()
{
//employee_id, name, date of birth, email, residential address, job title, salary
Console.Write("Employee id:");
int id = Convert.ToInt32(Console.ReadLine());
Console.Write("Employee Name:");
string name = Console.ReadLine();
Console.Write("Date of Birth:");
string dob = Console.ReadLine();
Console.Write("Email:");
string mail = Console.ReadLine();
Console.Write("Resident Address:");
string add = Console.ReadLine();
Console.Write("Job Title:");
string job = Console.ReadLine();
Console.Write("Salary:");
string sal = Console.ReadLine();
string filepath = @"C:/Users/szain/Desktop/9th Semester/Cp Lab/Lab12/abc.txt";
using (StreamWriter writer1 = new StreamWriter(filepath, append: true))
{
writer1.WriteLine(Convert.ToString(id) + " " + name + " " + dob + " " + mail + " " + add +
" " + job + " " + sal);
}
// string path = "C:\\Users\\Writefile\\test.txt";
menu();
}
static public void read()
{
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(@"C:/Users/szain/Desktop/9th
Semester/Cp Lab/Lab12/abc.txt");
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
counter++;
}
file.Close();
System.Console.WriteLine("There were {0} lines.", counter);
menu();
}
static public void menu()
{
Console.WriteLine("************************************");
Console.WriteLine(" Emplyee Management System");
Console.WriteLine("************************************");
Console.WriteLine("\n\n");
Console.WriteLine("Press 1 to Enter Employee");
Console.WriteLine("Press 2 to View data");
int opt = Convert.ToInt32(Console.ReadLine());
if (opt == 1)
{
[Lab no.12] [Computer Programming]
[Filing]
adduser();
}
if (opt == 2)
{
read();
}
}
Output:
[Lab no.12] [Computer Programming]
[Filing]
Task No. 2: Design a program of Grocery items in which you have to take data of 15
items. Items includes (item_id, item name, date of manufacturing, date of expiration,
quantity, price…etc.). Save all the data in a txt file using StreamWriter and print the data
using StreamReader.
Solution:
class item
{
static public void additem()
{
Console.WriteLine("Item Id:");
string id = Console.ReadLine();
Console.WriteLine("Item name:");
string name = Console.ReadLine();
Console.WriteLine("Manufacturing Date:");
string mdate = Console.ReadLine();
Console.WriteLine("Date of expiration:");
string edate = Console.ReadLine();
Console.WriteLine("Quantity:");
string qty = Console.ReadLine();
Console.WriteLine("Price:");
string price = Console.ReadLine();
}
static public void read()
{
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(@"C:/Users/szain/Desktop/9th
Semester/Cp Lab/Lab12/items.txt");
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
counter++;
}
file.Close();
System.Console.WriteLine("There were {0} lines.", counter);
menus();
}
static public void menus()
{
[Lab no.12] [Computer Programming]
[Filing]
Console.WriteLine("************************************");
Console.WriteLine(" Emplyee Management System");
Console.WriteLine("************************************");
Console.WriteLine("\n\n");
Console.WriteLine("Press 1 to add items");
Console.WriteLine("Press 2 to View data");
int opt = Convert.ToInt32(Console.ReadLine());
if (opt == 1)
{
additem();
}
if (opt == 2)
{
read();
}
}
static public void Ming()
{
menus();
}
Output: