7) Explain Falg iOS:: Binary and iOS::ate
7) Explain Falg iOS:: Binary and iOS::ate
A flag looks like ios::app if you’re using a compiler that is not fully ANSI-compliant, or
looks like ios_base::app if you’re using one that is fully ANSI-compliant. This particular
flag means that you want to write to a file, but you want to append to any existing data
that may already be in a file. You supply this flag as an argument of the constructor
for ofstream, as in either of the following examples:
12) explain the function used to read and write data in binary file.
When a program is terminated, the entire data is lost. Storing in a file will
preserve your data even if the program terminates.
If you have to enter a large number of data, it will take a lot of time to enter
them all.
However, if you have a file containing all the data, you can easily access the
contents of the file using a few commands in C.
You can easily move your data from one computer to another without any
changes
13) what is difference between manipulator and iOS member function in implementation? Give
examples.
we can not create own ios functions while we can create our own
manipulators.
17) explain the use of use of binary files in c++ with a program
struct Person
{
char name[50];
int age;
char phone[24];
};
int main()
{
Person me = {"Robert", 28, "364-2534"};
Person book[30];
int x = 123;
double fx = 34.54;
ofstream outfile;
outfile.open("junk.dat", ios::binary | ios::out);
outfile.write(&x, sizeof(int)); // sizeof can take a type
outfile.write(&fx, sizeof(fx)); // or it can take a variable name
outfile.write(&me, sizeof(me));
outfile.write(book, 30*sizeof(Person))
outfile.close();
}
20) write a program to store employee names with their designation and net pay to file a console also
display employee details from file .create a class employee.
class Employee
{
public string name;
public int salary;
public int joiningDate;
public Employee()
{
}
public Employee(string name, int salary, int joiningDate)
{
this.name = name;
this.salary = salary;
this.joiningDate = joiningDate;
}
public void GetEmployeeData()
{
{
Console.WriteLine("Enter the name of employee: ");
name = Convert.ToString(Console.ReadLine());
Console.WriteLine("Enter the salary of employee: ");
salary = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the date of joining of employee: ");
joiningDate = Convert.ToInt32(Console.ReadLine());
}
}
public void DisplayEmployee()
{
Console.WriteLine("The name of employee is: "+ name);
Console.WriteLine("The salary of employee is: "+salary);
Console.WriteLine("The date of joining of employee is: "+joiningDate);
}
}
class Program
{
static void Main(string[] args)
{
Employee[] e = new Employee[10];
for(int i = 0; i < 10; i++)
{
Console.WriteLine($"Enter the data of employee with id: {i}
*****************************************");
e[i] = new Employee();
e[i].GetEmployeeData();
}
Console.WriteLine("***********The data of given employees is: ");
for(int i = 0; i < 10; i++)
{
e[i].DisplayEmployee();
}
}
}