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 a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
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 an Assembly code to input two integer numbers from keyboard, computes the division of two...
Write an Assembly code to input two integer numbers from keyboard, computes the division of two numbers WITHOUT using division operator and print out the reminder and quotient to the screen. Note: program using “division operator” will earn no credit for this task. You are ALLOWED to use the “print” and “read” macro
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 prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Question 1: Write a C program that reads a date from the keyboard and tests whether...
Question 1: Write a C program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid month...
Write a C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT