Question

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 total letters would you like to store? [user types: 26]

Output (in the file, not in the console window)

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Notes and Hints:

1) Test your program with std::cout. If the correct letters show up, then delete (or comment out) that statement and switch it to the one that outputs to the file.

2) I know there are only 26 letters in the alphabet, but don't worry about the validating user's input for this basic exercise.

3) Mimir's feedback in the test cases is a bit confusing for this type of question. Pay attention to the Input and Output I wrote for you at the top of each test case.

the program will be tested as follows

USER INPUT: 26 // OUTPUT (in your letters.txt file): A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

USER INPUT: 5 // OUTPUT (in your letters.txt file): A B C D E

USER INPUT: 3 // OUTPUT (in your letters.txt file): A B C

USER INPUT: 0 // OUTPUT (in your letters.txt file):

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program screenshot:

Sample Output:

Sample Output file: letters.txt

Code to Copy:

// Declare the necessary header files.

#include <iostream>

#include <fstream>

// Start the main function.

int main()

{

// Declare the object of ofstream class.

std::ofstream out_file;

// open file.

out_file.open("letters.txt");

// Initialize the first character.

char a = 'A';

// Declare variable.

int ch;

// prompt the user to enter number

std::cout << "Including 'A', how many total letters would you like to store? ";

std::cin >> ch;

// Start the for loop

for (int i = 0; i < ch; i++)

{

// Display character.

out_file << (char)(a + i) << " ";

}

out_file << std::endl;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
This is a c++ question note: not using  namespace std; at the beginning of the program Writing...
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
  • This is a C++ question we do not use namespace std at the beginning of the...

    This is a C++ question we do not use namespace std at the beginning of the program 9. Arrays: Functions and Reading From File Although this code is a little long, the strategy is straightforward and it will really help you practice functions. I have provided a large amount of detail to help you out. In a nutshell, you're going to read some numbers from a file (into an array) and then ask the user for a number that will...

  • In C language This program reads in a series of words. All words consist of only...

    In C language This program reads in a series of words. All words consist of only lower-case letters ('a' through 'z'). None of the words entered will be longer than 50 letters. The program reads until ctrl-d (end-of-file), and then prints out all the lower-case letters that were missing in the input or a statement indicating the input has all the letters. Two executions of the program are shown below. Enter your input: the quick brown fox jumps over the...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Following should be done in C++: Create a program that reads a text file and prints...

    Following should be done in C++: Create a program that reads a text file and prints out the contents of the file but with all letters converted to uppercase. The name of the file to be read by the program will be provided by the user. Here are some example session: Contents of "data.txt": Hello, World! User input: data.txt Program output: HELLO, WORLD! Contents of "data.txt": tHiS FiLe HaS mIxEd CaSeS User input: data.txt Program output: THIS FILE HAS MIXED...

  • c++ Note: Do not use using namespace std; Use std:: Use comments for clear understanding TEST...

    c++ Note: Do not use using namespace std; Use std:: Use comments for clear understanding TEST THE PROGRAM. 1) Create a c++ program to run a simple experiment to see how reference parameters work. 2) You need to add a “&” symbol after the parameter type specification to set up a reference parameter: int myfunc (int & x) { x = 11; return -11; } int testdata = 0; int y; y= myfunc (testdata); 3) Now, You can get a...

  • In c++ #include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your...

    In c++ #include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your code 9 int main) 4 6 8 1e set <double, greater<double>>valuesA --1.1, 2.9, -2.3, 2.71 J: set <double, greater<double>> valuesB -3.14, 2.71, -3.88, 2.19; double value; cin > value; 12 13 14 15 16 17 18 19 /your code return ; Scenario Write a program that creates two sets (the sets are given in the code below) and asks the user for a number....

  • Write a program that will take input from a file of numbers of type double and...

    Write a program that will take input from a file of numbers of type double and output the average of the numbers in the file to the screen. Output the file name and average. Allow the user to process multiple files in one run. Part A use an array to hold the values read from the file modify your average function so that it receives an array as input parameter, averages values in an array and returns the average Part...

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