• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
We provide free Laptop reparing course for How to repair laptop motherboard with schematics diagram, bios and boardviews like lqv.com

DisplayMonk

Solution to your problem

  • Home
    • Privacy Policy
  • About Us
  • Repair Tips
  • Schematics Bios
  • Course
  • Online Jobs
  • Tools
  • Enquiry / Contact
Home » Laptop Desktop Motherboard repairing » FYIT Mumbai University practicals solutions all updated 2023

FYIT Mumbai University practicals solutions all updated 2023

April 15, 2023 by displaymonk

below are practicals and their solutions for Mumbai University FYBsc information technology 2023 updated complete list.

Aim : Write a C++ program to create a simple calculator.

Code:

# include <iostream>

using namespace std;

int main() {

  char op;

  float num1, num2;

  cout << “Enter operator: +, -, *, /: “;

  cin >> op;

  cout << “Enter two operands: “;

  cin >> num1 >> num2;

  switch(op) {

    case ‘+’:

      cout << num1 << ” + ” << num2 << ” = ” << num1 + num2;

      break;

    case ‘-‘:

      cout << num1 << ” – ” << num2 << ” = ” << num1 – num2;

      break;

    case ‘*’:

      cout << num1 << ” * ” << num2 << ” = ” << num1 * num2;

      break;

    case ‘/’:

      cout << num1 << ” / ” << num2 << ” = ” << num1 / num2;

      break;

    default:

      cout << “Error! operator is not correct”;

      break;

  }

  return 0;

}

Output :

Aim : Write a C++ program to convert seconds into hours, minutes and seconds.

Code :

#include<iostream>

using namespace std;

int main(){

  cout << “Enter total seconds”;

  int totalSeconds;

  cin >> totalSeconds;

  int hours = totalSeconds / 3600;

  int minutes = (totalSeconds % 3600) / 60;

  int seconds = totalSeconds % 60;  

  cout << “\n Hours : ” <<hours<<” | Minutes : “<<minutes<<” | Seconds : ” << seconds << endl;  

}

Output :

Aim : Write a C++ program to find the volume of a square, cone, and rectangle.

Code :

#include <iostream>

#include <string.h>

using namespace std;

int main ()

   {

      const float pi = 3.14159;

      float R, H, V;

      cout << “Input Cone’s radius: “;

      cin >> R;

      cout << “Input Cone’s height: “;

      cin >> H;

    // Cone’s volume.

    V = (1.0/3.0)*pi*(R*R)*H;

    cout << “The volume of the cone is: ” << V ;

    return 0;

}

Output :

Code :

#include <iostream>

#include <string>

using namespace std;

int main ()

{

  float S, V;

  cout << “Input Square’s side: “;

  cin >> S;

  // Square’s volume.

  V = S*S*S;

  cout << “The volume of the square is: ” << V ;

  return 0;

}

Output :

Code :

#include <iostream>

#include <string>

using namespace std;

int main ()

{

  const float pi = 3.14159;

  float L, W, H, V;

  cout << “Input Rectangle’s length: “;

  cin >> L;

  cout << “Input Reactangle’s height: “;

  cin >> H;

  cout << “Input Reactangle’s width: “;

  cin >> W;

  // Rectangle’s volume.

  V = L*W*H;

  cout << “The volume of the cone is: ” << V ;

  return 0;

}

Output :

Aim : Write a C++ program to find the greatest of three numbers.

Code :

#include <iostream>

using namespace std;

int main() {

    double n1, n2, n3;

    cout << “Enter three numbers: “;

    cin >> n1 >> n2 >> n3;

    if(n1 >= n2 && n1 >= n3)

        cout << “Largest number: ” << n1;

    else if(n2 >= n1 && n2 >= n3)

        cout << “Largest number: ” << n2;

    else

        cout << “Largest number: ” << n3;

    return 0;

}

Output :

Aim : Write a C++ program to find the sum of even and odd n natural numbers

Code :

#include<iostream>

using namespace std;

int main()

{

                int number, maximum, evenSum = 0, oddSum = 0;

                cout << “\nPlease Enter the Maximum Limit for Even & Odd Numbers  =  “;

                cin >> maximum;            

                for(number = 1; number <= maximum; number++)

                {

                                if ( number % 2 == 0 )

                                {

                                                evenSum = evenSum + number;

                                }

                                else

                                {

                                                oddSum = oddSum + number;

                                }

                }

                cout << “\nThe Sum of All Even Numbers upto ” << maximum << ” = ” << evenSum;

                cout << “\nThe Sum of All Odd Numbers upto ” << maximum << ”  = ” << oddSum;

                return 0;

}

Output :

Aim : Write a C++ program to find the sum of even and odd n natural numbers.

Code :

#include<iostream>

using namespace std;

int main()

{

                int number, maximum, evenSum = 0, oddSum = 0;

                cout << “\nPlease Enter the Maximum Limit for Even & Odd Numbers  =  “;

                cin >> maximum;            

                for(number = 1; number <= maximum; number++)

                {

                                if ( number % 2 == 0 )

                                {

                                                evenSum = evenSum + number;

                                }

                                else

                                {

                                                oddSum = oddSum + number;

                                }

                }

                cout << “\nThe Sum of All Even Numbers upto ” << maximum << ” = ” << evenSum;

                cout << “\nThe Sum of All Odd Numbers upto ” << maximum << ”  = ” << oddSum;

                return 0;

}

Output :

Aim : Write a C++ program to generate all the prime numbers between 1 and n, where n is a value supplied by the user.

Code :

#include <iostream>

using namespace std;

int main() {

    int num, i, upto;

    cout << “Find prime numbers upto : “;

    cin >> upto;

    cout << endl << “All prime numbers upto ” << upto << ” are : ” << endl;

    for(num = 2; num <= upto; num++) {

        for(i = 2; i <= (num / 2); i++) {

            if(num % i == 0) {

                i = num;

                break;

            }

        }

        if(i != num) {

            cout << num << ” “;

        }

    }

    return 0;

}

Output :

Aim : Write a C++ program using classes and object Student to print name of the student, roll_no. Display the same.

Code :

#include <iostream> 

using namespace std; 

class Student { 

   public: 

       int id;

       string name;

       int roll_no; 

       void insert(int i, string n, int rn)   

        {   

            id = i;   

            name = n;   

            roll_no = rn; 

        }   

       void display()   

        {   

            cout<<” ID is: “<<id<<”  Name is: “<<name<<” Roll number is: “<<roll_no<<endl;   

        }   

}; 

int main(void) { 

    Student s1;   

    Student s2;

                s1.insert(201, “Sonali”, 11);   

    s2.insert(202, “Arnav”, 12);   

    s1.display();   

    s2.display();   

    return 0; 

} 

Output :

Aim : Write a C++ program for Structure bank employee to print name of the employee, account_no. and balance. Display the same also display the balance after withdraw and deposite.

Code :

#include<iostream>

#include<stdio.h>

#include<string.h>

using namespace std;

class bank

{

        int acno;

        char nm[100], acctype[100];

        float bal; 

   public:

        bank(int acc_no, char *name, char *acc_type, float balance)

        {

                acno=acc_no;

                strcpy(nm, name);

                strcpy(acctype, acc_type);

                bal=balance;

        }

        void deposit();

        void withdraw();

        void display();

};

void bank::deposit()

{

        int damt1;

        cout<<“\n Enter Deposit Amount = “;

        cin>>damt1;

        bal+=damt1;

}

void bank::withdraw()

{

        int wamt1;

        cout<<“\n Enter Withdraw Amount = “;

        cin>>wamt1;

        if(wamt1>bal)

                cout<<“\n Cannot Withdraw Amount”;

        bal-=wamt1;

}

void bank::display()

{

        cout<<“\n ———————-“;

        cout<<“\n Accout No. : “<<acno;

        cout<<“\n Name : “<<nm;

        cout<<“\n Account Type : “<<acctype;

        cout<<“\n Balance : “<<bal; 

}

int main()

{

        int acc_no;

        char name[100], acc_type[100];

        float balance;

        cout<<“\n Enter Details: \n”;

        cout<<“———————–“;

        cout<<“\n Accout No. “;

        cin>>acc_no;

        cout<<“\n Name : “;

        cin>>name;

        cout<<“\n Account Type : “;

        cin>>acc_type;

        cout<<“\n Balance : “;

        cin>>balance;

        bank b1(acc_no, name, acc_type, balance);

        b1.deposit();

        b1.withdraw();

        b1.display();

        return 0;

}

Output :

Aim : Write a C++ Program to design a class having static member function named showcount() which has the property of displaying the number of objects created of the class.

Code :

#include <iostream>

using namespace std;

class My_Class{

   private:

      static int count;

   public:

      My_Class() { //in constructor increase the count value

         cout << “Calling Constructor” << endl;

         count++;

      } static int objCount() {

         return count;

      }

   };

int My_Class::count;

main() {

   My_Class my_obj1, my_obj2, my_obj3;

   int cnt;

   cnt = My_Class::objCount();

   cout << “Number of objects:” << cnt;

}

Output :

Aim : Write a Program to find Maximum out of Two Numbers using friend function.

Code :

#include<iostream>

using namespace std;

class Test {

private:

   int x, y;

public:

   void input() {

       cout << “Enter two numbers:”;

       cin >> x>>y;

   }

   friend void find(Test t);

};

void find(Test t) {

   if (t.x > t.y) {

       cout << “Largest is:” << t.x;

   } else {

       cout << “Largest is:” << t.y;

   }

}

int main() {

   Test t;

   t.input();

   find(t);

   return 0;

}

Output :

Aim : Write a C++ Program using copy constructor to copy data of an object to another object.

Code :

#include <iostream>

using namespace std;

class Point {

private:

    int x, y;

public:

    Point(int x1, int y1)

    {

        x = x1;

        y = y1;

    }

    Point(const Point& p1)

    {

        x = p1.x;

        y = p1.y;

    }

    int getX() { return x; }

    int getY() { return y; }

};

int main()

{

    Point p1(10, 15);

    Point p2 = p1;

    cout << “p1.x = ” << p1.getX() << “, p1.y = ” << p1.getY();

    cout << “\np2.x = ” << p2.getX() << “, p2.y = ” << p2.getY();

    return 0;

}

Output :

Aim : Write a C++ Program to allocate memory dynamically for an object of a given class using class’s construction.

Code :

#include <iostream>

using namespace std;

class geeks {

    const char* p;

public:

    geeks()

    {

        p = new char[6];

        p = “geeks”;

    }

    void display()

    {

        cout << p << endl;

    }

};

int main()

{

    geeks obj;

    obj.display();

}

Output :

Aim : Write a C++ program to design a class representing complex numbers and having the functionality of performing addition and multiplication of two complex numbers using operator overloading.

Code :

#include<iostream>

using namespace std;

class Complex

{

public:

int real,img;

void add(Complex c1,Complex c2)

{

int x,y;

x=c1.real+c2.real;

y=c1.img+c2.img;

cout<<“\n(“<<c1.real<<“+”<<c1.img<<“i)+(“<<c2.real<<“+”<<c2.img<<“i)=(“<<x<<“+”<<y<<“i)”;

}

void multiply(Complex c1,Complex c2)

{

int x,y;

x=c1.real*c2.real-c1.img*c2.img;

y=c1.real*c2.img+c1.img*c2.real;

cout<<“\n(“<<c1.real<<“+”<<c1.img<<“i)*(“<<c2.real<<“+”<<c2.img<<“i)=(“<<x<<“+”<<y<<“i)”;

}

Complex operator ++()

{

Complex x;

x.real=++real;

x.img=++img;

return x;

}

};

int main ()

{

Complex a,b,c,d,e;

cout<<“\nEnter real and imaginary part of first complex number:”;

cin>>a.real>>a.img;

cout<<“\nEnter real and imaginary part of second complex number:”;

cin>>b.real>>b.img;

c.add(a,b);

d.multiply(a,b);

cout<<“\n++(“<<a.real<<“+”<<a.img<<“i)=(“;

++a;

cout<<a.real<<“+”<<a.img<<“i)”;

return 0;

}

Output :

Aim : Write a C++ program to overload new/delete operate in a class.

Code :

#include<iostream>

#include<stdlib.h>

using namespace std;

class student

{

    string name;

    int age;

public:

    student()

    {

        cout<< “Constructor is called\n” ;

    }

    student(string name, int age)

    {

        this->name = name;

        this->age = age;

    }

    void display()

    {

        cout<< “Name:” << name << endl;

        cout<< “Age:” << age << endl;

    }

    void * operator new(size_t size)

    {

        cout<< “Overloading new operator with size: ” << size << endl;

        void * p = ::operator new(size);       

       return p;

    }

    void operator delete(void * p)

    {

        cout<< “Overloading delete operator ” << endl;

        free(p);

    }

};

int main()

{

    student * p = new student(“Yash”, 24);

    p->display();

    delete p;

}

Output :

Aim : Write a C++ program to accesss members of a STUDENT class using pointer to object members.

Code :

#include <iostream>

using namespace std;

class Box {

   public:

      // Constructor definition

      Box(double l = 2.0, double b = 2.0, double h = 2.0) {

         cout <<“Constructor called.” << endl;

         length = l;

         breadth = b;

         height = h;

      }

      double Volume() {

             return length * breadth * height;

      }

   private:

      double length;     // Length of a box

      double breadth;    // Breadth of a box

      double height;     // Height of a box

};

int main(void) {

   Box Box1(3.3, 1.2, 1.5);   

   Box Box2(8.5, 6.0, 2.0);   

   Box *ptrBox;  

   ptrBox = &Box1;  

   cout << “Volume of Box1: ” << ptrBox->Volume() << endl;

   ptrBox = &Box2;

   cout << “Volume of Box2: ” << ptrBox->Volume() << endl;

   return 0;

}

Output :

Aim : Write a C++ Program to generate Fibonacci Series by using Constructor to initialize the Data Members.

Code :

#include<iostream>

using namespace std;

class fibonacci

{

    long int a,b;

    public:

    fibonacci()

    {

        a=-1;

        b=1;

    }

    void fibseries(int n)

    {

        int i,next;

        cout<<“\n Resultant fibonacci series”;

        cout<<“\n—————————–\n”;

        for(i=0;i<n;i++)

        {

            next=a+b;

            cout<<next<<endl;

            a=b;

            b=next;

        }

    }

};

int main()

{

    fibonacci f;

    int n;

    cout<<“\n Fibonacci series \n”;

    cout<<“\n Enter the range = \n”;

    cin>>n;

    f.fibseries(n);

    return 0;

}

Output :

Aim : Write a C++ Program that illustrate single inheritance.

Code :

#include <iostream>

using namespace std;

class base  

{

   public:

     int x;

   void getdata()

   {

     cout << “Enter the value of x = “;

                 cin >> x;

   }

 };

class derive : public base  

{

   private:

    int y;

   public:

   void readdata()

   {

     cout << “Enter the value of y = “; cin >> y;

   }

   void product()

   {

     cout << “Product = ” << x * y;

   }

 };

 int main()

 {

    derive a;

    a.getdata();

    a.readdata();

    a.product();

    return 0;

 }     

Output :

Aim : Write a C++ Program that illustrate multiple inheritance.

Code :

#include<iostream>

using namespace std;

class A

{

public:

  A()  { cout << “A’s constructor called” << endl; }

};

class B

{

public:

  B()  { cout << “B’s constructor called” << endl; }

};

class C: public B, public A  // Note the order

{

public:

  C()  { cout << “C’s constructor called” << endl; }

};

int main()

{

    C c;

    return 0;

}

Output :

Aim :  Write a C++ Program that illustrate multi level inheritance.

Code :

#include <iostream>

using namespace std;

class Vehicle{

   public:

      void vehicle(){

         cout<<“I am a vehicle\n”;

      }

};

class FourWheeler : public Vehicle{

   public:

      void fourWheeler(){

         cout<<“I have four wheels\n”;

      }

};

class Car : public FourWheeler{

   public:

      void car(){

         cout<<“I am a car\n”;

      }

};

int main(){

   Car obj;

   obj.car();

   obj.fourWheeler();

   obj.vehicle();

   return 0;

}

Output :

Aim : Write a C++ Program that illustrate Hierarchical inhertitance.

Code :

#include <iostream>

using namespace std;

class A

{

    public:

                int x, y;

                void getdata()

                {

                    cout << “\nEnter value of x and y:\n”; cin >> x >> y;

                }

};

class B : public A

{

    public:

                void product()

                {

                    cout << “\nProduct= ” << x * y;

                }

};

class C : public A

{

    public:

                void sum()

                {

        cout << “\nSum= ” << x + y;

                }

};

int main()

{

    B obj1;        

    C obj2;        

    obj1.getdata();

    obj1.product();

    obj2.getdata();

    obj2.sum();

    return 0;

} 

Output :

Aim : Write a C++ Program illustrating how the constructors are implemented the order in which they are called when the classes are inherited. Use three classes named alpha, beta, gamma such that alpha, beta are base class and gamma is derived class inheriting alpha and beta.

Code :

#include <iostream>

using namespace std;

class Alpha

{

        int x;

        public:

                // constructors

                Alpha(int i)

                {

                        x = i;

                        cout << “\n Alpha constructed”;

                }

               void show_alpha()

               {

                      cout << ” X = ” << x << “\n”;

               }

};

class Beta : public Alpha

{

       float p, q;

       public:

                  // Constructor

                Beta(int i, float a, float b):Alpha(i), p(a), q(b+p)

                {

                       cout << “\n Beta Constructed”;

                }

                void show_beta()

                {

                       cout << ” P = ” << p << “\n”;

                       cout << ” Q = ” << q << “\n”;

                }

};

class delta

{

       int d;

       public:

                 delta(int a) { d = a; cout << “\n Delta Constructed”;}

                 void show_delta()

                 {

                         cout << ” d = ” << d << “\n”;

                 }

};

class Gamma : public Beta, public delta

{

        int u, v;

        public:

                  // Constructor

                  Gamma(int a, int b, float c): Beta(a,c,c), delta(a), u(a)

                   {

                            v = b;

                           cout << “\n Gamma constructed”;

                   }

                  void show_gamma()

                  {

                           cout << ” U = ” << u << “\n”;

                           cout << ” V = ” << v << “\n”;

                  }

};

int main()

{

        Gamma g(2, 4, 2.5);

        cout << “\n\n Display member values ” << “\n\n”;

        g.show_alpha();

        g.show_beta();

        g.show_delta();

        g.show_gamma();

   return 0;

}

Output :

Aim : Write a C++ Program to design a student class represing student roll no. and a test class (derived class of student) representing the scores of the student in various subjects and sports class representing the score in sports. The sports and test class should be inherited by a result class having the functionality to add the scores and display the final result for a student.

Code :

#include<iostream>

using namespace std;

class student

{

 protected:

 int roll_number;

 public:

 void get_number(int a)

 {

  roll_number = a;

 }

 void put_number(void)

 {

  cout<<“Roll No:”<<roll_number<<“\n”;

 }

};

class test : public student

{

 protected:

 float part1, part2;

 public:

 void get_marks(float x, float y)

 {

  part1 = x;

  part2 = y;

 }

 void put_marks(void)

 {

  cout<<“Marks obtained”<<“\n”<<“part1 =”<<part1<<“\n”<<“part2 =”<<part2<<“\n”;

 }

};

class sports

{

 protected:

 float score;

 public:

 void get_score(float s)

 {

  score = s;

 }

 void put_score(void)

 {

 cout<<“Sports wt:”<<score<<“\n\n”;

 }

};

class result : public test, public sports

{

 float total;

 public:

 void display(void);

};

void result ::display(void)

{

 total = part1 + part2 + score;

 put_number();

 put_marks();

 put_score();

 cout<<“Total Score:”<<total<<“\n”;

}

int main()

{

 result student_1;

 student_1.get_number (1234);

 student_1.get_marks (27.5, 33.0);

 student_1.get_score (6.0);

 student_1.display ();

 return 0;

}

Output :

Aim : Write a C++ program to maintain the records of person with details (Name and Age) and find the eldest among them. The program must use the pointer to return the result.

Code :

#include<iostream>

using namespace std;

class Records

{

    int age;

    string name;

    public:

        Records() {};

        Records(string n,int a): name(n),age(a) {}

        void show()

        {

            cout<<name<<” : “<<age<<endl;

        }

        Records eldest(Records o)

        {

            return (o.age>age)? o: *this;

        }

};

int main()

{

    Records ob[3] = { Records(“Ani”,21), Records(“Arka”,50), Records(“Ram”,30) };

    Records res = ob[0];

    for(int i = 0 ; i<2; i++){

                res = res.eldest(ob[i+1]);

                }

    res.show();

    return 0;

}

Output :

Aim : Write a C++ program illustrating the use of virtual function in class.

Code :

#include <iostream>

using namespace std;

class Base{

public:

virtual void Output(){

cout << “Output Base class” << endl;

}

void Display(){

cout << “Display Base class” << endl;

}

};

class Derived : public Base{

public:

void Output(){

cout << “Output Derived class” << endl;

}

void Display()

{

cout << “Display Derived class” << endl;

}

};

int main(){

Base* bpointr;

Derived dpointr;

bpointr = &dpointr;

// binding virtually

bpointr->Output();

// binding non-virtually

bpointr->Display();

}

Output :

 Aim : Write a C++ program to design a class representing the information regarding digital library (books, tape: book & tape should be seperate classes having the base class as a media). The class should have the functionality for adding new item, issuing, deposite, etc. the program should use the runtime polymorphism.

Code :

#include<iostream>

#include<string>

#include <cstring>

using namespace std;

class media

{

 protected:

 char title[50];

 float price;

 public:

 media(char *s, float a)

 {

  strcpy(title, s);

  price = a;

 }

 virtual void display(){}

};

class book : public media

{

 int pages;

 public:

 book(char *s, float a, int p) : media(s,a)

 {

  pages = p;

 }

 void display();

};

class tape : public media

{

 float time;

 public:

 tape(char * s, float a, float t):media(s,a)

 {

  time =t;

 }

 void display();

};

void book ::display()

{

 cout<<“\n Title:”<<title;

 cout<<“\n Pages:”<<pages;

 cout<<“\n Price:”<<price;

}

void tape ::display ()

{

 cout<<“\n Play Time:”<<time<<“mins”;

 cout<<“\n Price:”<<price;

}

int main()

{

 char * title = new char[30];

 char * title1 = new char[30];

 float price, time;

 int pages;

 cout<<“\n Enter Book Details \n”;

 cout<<“\n Title:”;

 gets(title);

 cout<<“\n Price:”;

 cin>>price;

 cout<<“\n Pages:”;

 cin>>pages;

 book book1(title, price, pages);

 cout<<“\n Enter Tape Details”;

 cout<<“\n Price:”;

 cin>>price;

 cout<<“\n Play Times(mins):”;

 cin>>time;

 tape tape1(title1, price, time);

 media* list[2];

 list[0] = &book1;

 list[1] = &tape1;

 cout<<“\n Media Details”;

 cout<<“\n…………..Book…..”;

 list[0]->display();

 cout<<“\n…………..Tape…..”;

 list[1]->display();

 return 0;

}

Output:

Aim: Write a C++ program to show conversion from string to int and vice-versa.

a) String to Number conversion :-

Code :

#include<iostream>

#include<cstdlib>

using namespace std;

main() {

   int n;

   char num_string[20] = “1234”;

   n = atoi(num_string);

   cout << n;

}

Output :

b) Number to string conversion

Code :

#include<stdio.h>

main() {

   char str[20];

   float number;

   printf(“Enter a number: “);

   scanf(“%f”, &number);

   sprintf(str, “%f”, number);//number into string using sprintf

   printf(“You have entered: %s”, str);

}

Aim : Write a C++ program to implement basic operation of class ios i.e. elf, unself, precision, etc.

Code :

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

    cout << “Example for formatted IO” << endl;

    cout << “Default: ” << endl;

    cout << 123 << endl;

    cout << “width(5): ” << endl;

    cout.width(5);

    cout << 123 << endl;

    cout << “width(5) and fill(‘*’): ” << endl;

    cout.width(5);

    cout.fill(‘*’);

    cout << 123 << endl;

    cout.precision(5);

    cout << “precision(5) —> ” << 123.4567890 << endl;

    cout << “precision(5) —> ” << 9.876543210 << endl;

    cout << “setf(showpos): ” << endl;

    cout.setf(ios::showpos);

    cout << 123 << endl;

    cout << “unsetf(showpos): ” << endl;

    cout.unsetf(ios::showpos);

    cout << 123 << endl;

    return 0;

}

Output : 

Aim : Write a C++ program to implement I/O operations includes inputting a string, Calculating length of the string, Storing the String in a file, fetching the stored characters from it, etc.

Code :

 #include<iostream>

#include<fstream>

#include<string>

using namespace std;

struct customer

{

   char name[20];

   float balance;

};

int main()

{

   customer savac;

   cout<<“Enter your name: “;

   cin.get(savac.name, 20);

   cout<<“Enter balance: “;

   cin>>savac.balance;

   ofstream fout;

   fout.open(“Saving”, ios::out | ios::binary);    // open file

   if(!fout)

   {

      cout<<“File can\’t be opened..!!\n”;

      cout<<“Press any key to exit…\n”;

      exit(1);

   }

   fout.write((char *) & savac, sizeof(customer));    // write

   fout.close();     // connection

   // read

   ifstream fin;

   fin.open(“Saving”, ios::in | ios::binary);    // open

   fin.read((char *) & savac, sizeof(customer));     // read

   cout<<savac.name;            // display structure

   cout<<” has the balance amount of Rs. “<<savac.balance<<“\n”;

   fin.close();

   cout<<“\nPress a key to exit…\n”;

}

Output :

Aim : Write a Program to copy the contents of one file to another.

Code :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    fstream f1;

    fstream f2;

    string ch;

    f1.open(“file1.txt”, ios::in);

    // opening second

    f2.open(“file2.txt”, ios::out);

    while (!f1.eof()) {

        // extracting line by line

        getline(f1, ch);

        // writing line by line

        f2 << ch << endl;

    }

    // closing

    f1.close();

    f2.close();

    // opening and read

    f2.open(“file2.txt”, ios::in);

    while (!f2.eof()) {

        getline(f2, ch);

        cout << ch << endl;

    }

    f2.close();

    return 0;

}

Output :

Aim : Write a C++ program to perform read/write binary I/O operation on a file. (i.e. write the object of a structure/class to file).

Code :

#include <iostream>

#include <fstream>

#define FILE_NAME “emp.dat”

using namespace std;

//class employee declaration

class Employee {

private :

                int           empID;

                char       empName[100] ;

                char       designation[100];

                int           ddj,mmj,yyj;

                int           ddb,mmb,yyb;

public  :

                //function to read employee details

                void readEmployee(){

                                cout<<“EMPLOYEE DETAILS”<<endl;

                                cout<<“ENTER EMPLOYEE ID : ” ;

                                cin>>empID;

                                cin.ignore(1);

                                cout<<“ENTER  NAME OF THE EMPLOYEE : “;

                                cin.getline(empName,100);

                                cout<<“ENTER DESIGNATION : “;

                                cin.getline(designation,100);

                                cout<<“ENTER DATE OF JOIN:”<<endl;

                                cout<<“DATE : “; cin>>ddj;

                                cout<<“MONTH: “; cin>>mmj;

                                cout<<“YEAR : “; cin>>yyj;

                                cout<<“ENTER DATE OF BIRTH:”<<endl;

                                cout<<“DATE : “; cin>>ddb;

                                cout<<“MONTH: “; cin>>mmb;

                                cout<<“YEAR : “; cin>>yyb;

                }

                //function to write employee details

                void displayEmployee(){

                                cout<<“EMPLOYEE ID: “<<empID<<endl

                                 <<“EMPLOYEE NAME: “<<empName<<endl

                                 <<“DESIGNATION: “<<designation<<endl

                                 <<“DATE OF JOIN: “<<ddj<<“/”<<mmj<<“/”<<yyj<<endl

                                 <<“DATE OF BIRTH: “<<ddb<<“/”<<mmb<<“/”<<yyb<<endl;

                }

};

int main(){

                //object of Employee class

                Employee emp;

                //read employee details

                emp.readEmployee();

                //write object into the file

                fstream file;

                file.open(FILE_NAME,ios::out|ios::binary);

                if(!file){

                                cout<<“Error in creating file…\n”;

                                return -1;

                }

                file.write((char*)&emp,sizeof(emp));

                file.close();

                cout<<“Date saved into file the file.\n”;

                //open file again

                file.open(FILE_NAME,ios::in|ios::binary);

                if(!file){

                                cout<<“Error in opening file…\n”;

                                return -1;

                }

                if(file.read((char*)&emp,sizeof(emp))){

                                                cout<<endl<<endl;

                                                cout<<“Data extracted from file..\n”;

                                                //print the object

                                                emp.displayEmployee();

                }

                else{

                                cout<<“Error in reading data from file…\n”;

                                return -1;

                }

                file.close();        

                return 0;

}

Output :

Filed Under: university students updated material Tagged With: FYIT Mumbai University practicals solutions all updated 2023

Primary Sidebar

Search On Website

Laptop Desktop Chip Level Help Guide

  • 15341 1 schematic boardview

    Schematic 15341-1 for Dell Inspiron 15 model motherboard

    November 10, 2023

  • rt809f programmer latest version

    Rt809h universal programmer latest software download free 

    June 7, 2023

  • RT809F Programmer Software free download – DisplayMonk

    RT809F Programmer Software free download – DisplayMonk

    June 7, 2023

  • RT809F Serial ISP BIOS Programmer Tool separate 1.8V Adapter and Latest Software Download

    RT809F Serial ISP BIOS Programmer Tool separate 1.8V Adapter and Latest Software Download

    May 29, 2023

  • free schematics bios boardviews

    Free schematics bios boardviews

    May 15, 2023

Footer

Mobile Repair

We do mobile repairing.

Learn more about mobile repairing service.

Laptop Repair

We laptop repairing.

Learn more about laptop repairing service.

TV Repair

We do TV repairing.

Learn more about tv repairing service.

Copyright © 2023 · DisplayMonk

  • Home
  • About Us
  • Repair Tips
  • Schematics Bios
  • Course
  • Online Jobs
  • Tools
  • Enquiry / Contact