Sunday, 5 August 2018

DS Malik Chapter 3 Question 18 Solution

Leave a Comment
Question :


Suppose that infile is an ifstream variable and it is associated with the file that contains the following data: 27306 savings 7503.35. Write the C++ statement(s) that reads and stores the first input in the int variable acctNumber, the second input in the string variable accountType, and the third input in the double variable balance.



Explanation:
Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int acctNumber;
    string accountType;
    double balance;

    ifstream infile("employee.dat");

    if(infile.is_open())
    {
        infile >> acctNumber;
        infile >> accountType;
        infile >> balance;

        infile.close();
    }

    cout << "acctNumber = " << acctNumber << endl
         << "accountType = " << accountType << endl
         << "balance = " << balance << endl
         << endl;

    return 0;
}

Output:


Related Articles:


DS Malik Fifth Edition Complete Solution Manual 

C++ Primer Plus Sixth Edition Complete Solution Manual 

C++ Books Solution

If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: