Question

In: Computer Science

in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard...

in c++

QUESTION 4:

Write the code to do the following:

-read input from the keyboard by displaying the message on the screen to ask and read the following information:

* customer ID (string)

* customer name (string)                                                       

* balance (float)

-open output file customer .txt to write

-Write to the output file customer.txt the following information:

                Customer ID – customer name – balance

For example:

1561175753 - James Smith – 1255.25

-close file

QUESTION 5:

-create one notepad file named as data.txt and type the following lines:

1112243433 - Mary Lane – 1250.366

2123312344 – John Smith – 2134.25

1561175753 - James Smith – 1255.25           

-provide the C++ code to open above file data.txt

-Read each line of the file then display on screen

-continue reading and displaying on the screen all the lines until end of the file

-Write: “End of the file data.txt” on the screen

-close data.txt file

Solutions

Expert Solution

Given code is in C++:

Q4.)

#include <iostream>
#include <stdio.h>
#include <string>
#include <fstream>          //this header is used whenever we want to work with files.

using namespace std;

int main()
{
    string id, name, surname;                        //declaring id, name and surname strings.
    float balance;                                   //declaring the balance variable.
    cout<<"Enter the customer ID: ";                 //taking inputs for the id, name, surname and balance.
    cin>>id;
    cout << "Enter the customer name: ";
    cin >> name >>surname;
    cout << "Enter the balance: ";
    cin >> balance;
    

    ofstream myfile("customer.txt");        //create and open the customer.txt file

    myfile<<id<<"-"<<name<<" "<<surname<<"-"<<balance;        //writing to the file.

    myfile.close();                         //closing the file after writing to it.
    return 0;                               //terminating the program.
}

Output:

customer.txt:

Q5.)

#include <iostream>
#include <fstream>                   //this header is used whenever we want to work with files.
#include <stdio.h>

using namespace std;

int main()
{
    string text;                    //declaring a text string.

    ifstream readfile("data.txt");          //opening the file data.txt into readfile.

    while(getline(readfile, text))          //reading each line of the file into text string.  
    {
        cout<<text<<endl;                   //printing out the text string.
    }

    cout<<"End of the file data.txt";       

    readfile.close();                       //closing the file after reading it.
    return 0;                               //terminating the program.
}

Output:

Kindly like if this helps :)


Related Solutions

Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
Write code to read a list of song names and durations from input. Input first receives...
Write code to read a list of song names and durations from input. Input first receives a song name, then the duration of that song. Input example: Time 424 Money 383 quit. #include <iostream> #include <string> #include <vector> using namespace std; class Song { public: void SetNameAndDuration(string songName, int songDuration) { name = songName; duration = songDuration; } void PrintSong() const { cout << name << " - " << duration << endl; } string GetName() const { return name;...
Write a C++ function called parse that reads one line of user input from the keyboard...
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input.  Your function should be passed the array and a reference variable that is to be assigned the length of the array.  Prompt the user and read the input from within the function. For example:  If the user inputs copy this that, the resulting array would have length 3 and contain the strings “copy”, “this”, and “that”....
Write a driver to get a String input from keyboard and if the input string has...
Write a driver to get a String input from keyboard and if the input string has less than 10 characters, throw a StringTooShortException. public class StringTooShortException extends Exception {     //-----------------------------------------------------------------     // Sets up the exception object with a particular message.     //-----------------------------------------------------------------     public StringTooShortException()     {         super("String does not have enough characters");     } }
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
Done in C++, Write a program to read the input file, shown below and write out...
Done in C++, Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets 6 Philadelphia 31, Tampa Bay 20 Green Bay 19,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT