Professional Documents
Culture Documents
Co3 Ass
Co3 Ass
Co3 Ass
Pooja
1. Write a console application for reading student name, Reg.no, Dept, Gender, Native
place from the user and write the details into file in binary format use appropriate
reader and writer class? CO3
PROGRAM
using System;
using System.IO;
catch (IOException e)
{
Console.WriteLine("An IO Exception Occurred :" + e);
}
}
//Read from the file and store the values to the variables
string name = br.ReadString();
int regno = br.ReadInt32();
string dept = br.ReadString();
String native = br.ReadString();
char gender = br.ReadChar();
catch (IOException e)
{
Console.WriteLine("An IO Exception Occurred :" + e);
}
}
}
OUTPUT:
2. Write a c# program to create a file and directory and also write the appropriate
methods to get the following details in run time? CO3
REGISTER NO : 1612075 NAME: P.Pooja
using System.Linq;
using System.Text;
using System.IO;
namespace fileinfoclass1 {
class Program {
// Create Method
FileStream fs = fi.Create();
//CreateText Method
str.WriteLine("hello");
str.Close();
//Delete Method
REGISTER NO : 1612075 NAME: P.Pooja
fi.Delete();
//CreateText Method
fi1.CopyTo(path2);
// MoveTo Method
fi1.MoveTo(path2);
//ApendText Method
StreamWriter sw = fi.AppendText();
sw.WriteLine("This");
sw.WriteLine("is Extra");
sw.WriteLine("Text");
REGISTER NO : 1612075 NAME: P.Pooja
sw.Close();
// Opentext Method
StreamReader sr = fi.OpenText();
string s = "";
Console.WriteLine(s);
3. What is serialization? List the types of Serialization Formatter and explain it with
an example program also define deserialization. CO3
The byte stream created is platform independent. So, the object serialized on one platform can be
deserialized on a different platform.
REGISTER NO : 1612075 NAME: P.Pooja
Advantages of Serialization
1. To save/persist state of an object.
2. To travel an object across a network.
Example 1:
// Java code for serialization and deserialization
// of a Java object
import java.io.*;
// Default constructor
public Demo(int a, String b)
{
this.a = a;
this.b = b;
}}
class Test
{
public static void main(String[] args)
{
Demo object = new Demo(1, "geeksforgeeks");
String filename = "file.ser";
// Serialization
try
{
REGISTER NO : 1612075 NAME: P.Pooja
out.close();
file.close();
// Deserialization
try
{
// Reading the object from a file
FileInputStream file = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(file);
in.close();
file.close();
catch(IOException ex)
{
System.out.println("IOException is caught");
}
catch(ClassNotFoundException ex)
{
System.out.println("ClassNotFoundException is caught");
}
REGISTER NO : 1612075 NAME: P.Pooja
}
}
Output :
Object has been serialized
Object has been deserialized
a=1
b = geeksforgeeks
4. Develop a C# Console Application to get the employee details such as name, ID,
Basic Pay, DA from the user and calculate the net salary of the employee and also
write these information into a file using StreamWriter Class and read the same data
using StreamReader Class. CO3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EmployeeIndexer
{
class Program
{
static void Main(string[] args)
{
while (true)
Console.Clear();
Console.WriteLine("Menu");
Console.WriteLine("====");
Console.WriteLine("3.Exit");
int ch = Int32.Parse(Console.ReadLine());
switch (ch)
{
REGISTER NO : 1612075 NAME: P.Pooja
case 1:
break;
case 2: