Question

C++ beginner question. Using C++ Mike has 7 friends. Create a loop that outputs his friends...

C++ beginner question. Using C++

  1. Mike has 7 friends. Create a loop that outputs his friends (A,B,C,D,E,F,G) to a file.
  2. Create a loop that reads his friends from a file and outputs their names to the console.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// do comment if any problem arises

//code

#include <iostream>

#include <fstream>

using namespace std;

int main(int argc, char const *argv[])

{

    // write to output.txt

    ofstream output("output.txt");

    // 7 friends

    output << "A B C D E F G";

    // close file

    output.close();

    // read output.txt

    ifstream input("output.txt");

    // output all friends

    cout << "Mike friends:\n";

    string friends;

    while (input >> friends)

    {

        cout << friends << endl;

    }

    return 0;

}

output.txt:

Output:

Add a comment
Know the answer?
Add Answer to:
C++ beginner question. Using C++ Mike has 7 friends. Create a loop that outputs his friends...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ in beginner form 1.) Create a function that takes in a number and outputs...

    Using C++ in beginner form 1.) Create a function that takes in a number and outputs a box of stars of that size. 2.) Create a function that takes in a number and outputs all the primes up until and including that number.

  • Using C++ 1. Create a while loop that counts even numbers from 2 to 10 2....

    Using C++ 1. Create a while loop that counts even numbers from 2 to 10 2. Create a for loop that counts by five (i.e. 0, 5, 10, ...) from 0 to 100 3. Ask for a person's age and give them three tries to give you a correct age (between 0 and 100) 4. Use a for loop to list Celsius and Fahrenheit temperatures. The "C" should be from -20 to 20 and the F should be shown correspondingly...

  • please solve it using c++ coding Write a C++ program that outputs a table having four...

    please solve it using c++ coding Write a C++ program that outputs a table having four columns of temperature values, ordered as follow: Celsius, Fahrenheit, Kelvin and Rankine. Use a while loop Let the Celsius temperature vary from 0.0 to 100.0 in steps of 5 °C. Convert each of these values to the other scales using the formulas given in Lab-1 (reproduced here for your convenience): 1) KELVIN CELSIUS FAHRENHEIT RAN KINE 31SOLS 2672 273 MELTS 32 a. Fahrenheit (F):...

  • derive the minimum SOP(Sum of Products) for the outputs a,b,c,d,e,f,g of the 7 segment display. show...

    derive the minimum SOP(Sum of Products) for the outputs a,b,c,d,e,f,g of the 7 segment display. show some work implement in logisim i derive the minimum SOP(Sum of Products) for the outputs a,b,c,d,e,f,g of the 7 segment display. show some work implement in logisim i Code converter 7-segment display

  • Write the code for a). to e) using VBA in excel

    write the code for a). to e) using VBA in excel : . a) Find the fifth customer whose first name starts vith ·K", and show his/her customer ID (using Do while ǐoop) ' b) Redo the above exercise with (Do Loop Until) c) Find how many Matthew are in the 1ist (using any loop you 1ike) and the same time find how many custoners are in the list ' Take care of your stop condition customerCounter - matthewCounter MsgBox...

  • Create a console application project and solution called “ConsoleWorkWithData.” using C# Create the following variables with...

    Create a console application project and solution called “ConsoleWorkWithData.” using C# Create the following variables with data type: a. FirstName: string data type b. LastName: string data type c. Student ID: int data type d. BirthDate: data time data type e. Grade: decimal data type Write all values in these variables to the screen in this format: a. --------------------------------------------------------- b. My name is Rieser Angie c. I’m a new student, and this is my first program d. ************************************** e. My...

  • This is a c++ question note: not using  namespace std; at the beginning of the program Writing...

    This is a c++ question note: not using  namespace std; at the beginning of the program Writing Data to a File This program will write a series of letters, starting with 'A', to an external file (letters.txt). The user will decide how many letters in total get saved to the file. ** IMPORTANT: The test cases will evaluate your code against .txt files that I uploaded. You do NOT have to upload your own txt files. Input: Including 'A', how many...

  • John and his friends wanted to see how their friends compared to the reading habits of...

    John and his friends wanted to see how their friends compared to the reading habits of U.S. citizens. They collected the following data from 10 of their friends. Did their friends read significantly more books than the rest of the citizens in the U.S.? (In 2017, U.S. citizens read an average of 12 books with a standard deviation of 4) Books Read 15 19 21 16 13 17 4 1 20 a. What is the correct test for this question?...

  • 8. Nick wants to visit some friend. Graph below represents distance to his friends. c. Nick...

    8. Nick wants to visit some friend. Graph below represents distance to his friends. c. Nick decides to go visit Bob. Given the following additional data about the number of stations it takes to travel between each friend's house, use Dijks- tra's algorithm to find the shortest path from Nick' to the Bob' house. When answering this question you must show every step in your calculations, in- cluding your final fully-labelled graph. Nick Fil L e ? William Marta stations...

  • CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities...

    CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities described below in a single source file Label each activity with its own heading using comments. Activities: 1) Favorite numbers a. Declare and initialize an array of 10 integers as a single statement using a name of your choice. b. Output the result of adding the 1st and 5th members of the array. C. Subtract the 4h member from 3 times the 10th member...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT