0% found this document useful (0 votes)
38 views8 pages

Zain Rizvi 02-134162-140 Lab 12

The document describes two tasks for a lab experiment on filing. Task 1 involves designing a program to take employee information like ID, name, DOB etc and save it to a text file. Task 2 involves designing a program to take grocery item information like ID, name, date etc and save it to a text file and also print the data using a StreamReader.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views8 pages

Zain Rizvi 02-134162-140 Lab 12

The document describes two tasks for a lab experiment on filing. Task 1 involves designing a program to take employee information like ID, name, DOB etc and save it to a text file. Task 2 involves designing a program to take grocery item information like ID, name, date etc and save it to a text file and also print the data using a StreamReader.

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 PDF, TXT or read online on Scribd
You are on page 1/ 8

Bahria University,

Karachi Campus

COURSE: CSC-113 COMPUTER PROGRAMMING


TERM: FALL 2019, CLASS: BSE- 1 (A)

Submitted By:

____Zain Rizvi________________________46064_______
(Name) (Reg. No.)
Submitted To:

Engr. Adnan ur rehman/ Engr. Ramsha Mashood

Signed Remarks: Score:


INDEX
SNO DATE LAB LAB OBJECTIVE SIGN
NO

1 3/oct/2020 1 Programming Basic

2 11/oct/2020 2 Variable and Arithmetic operation

3 18/oct/2020 3 input and output

4 27/oct/2020 4 Formatted output

5 28/Nov/2020 5 operations and Expressions

6 29/Nov/2020 6 conditional statement

7 8/Nov/2020 7 LOOP

8 13/Nov/2020 8 while and do-while Loops

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

LAB EXPERIMENT NO.


____12___
LIST OF TASKS
TASK NO OBJECTIVE

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
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.

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();
}
}

static public void empmenu() {


menu();
}

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();

string filepath = @"C:/Users/szain/Desktop/9th Semester/Cp Lab/Lab12/items.txt";


//FileStream stream = new FileStream(filepath, FileMode.OpenOrCreate);
using (StreamWriter writer1 = new StreamWriter(filepath,append:true))
{
//writer1.Write(String.Format("%20s %20s", "column 1", "column 2", "column 3", "column
4", "column 5", "column 6 \r\n"));
writer1.WriteLine(id + " " + name + " " + mdate + " " + edate + " " + qty + " " +
price);
}
// string path = "C:\\Users\\Writefile\\test.txt";
menus();

}
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:

You might also like