Question

In: Computer Science

This program will write a series of letters, starting with 'A', to an external file (letters.txt)....

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.

Starter Code:

// VARIABLES
// Creating file stream object for output

// INPUT
"Including 'A', how many total letters would you like to store? ";

cout << std::endl;

// OUTPUT LETTERS TO FILE
// Create and open letters.txt for output

YOUR_CODE << ' '; // output TO FILE
  

Solutions

Expert Solution

C++ PROGRAM

//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.
#include <iostream>
#include <fstream>

using namespace std;

int main()//main function
{
        ofstream File;//ofstream used to create file.
        int totalLetters;
        File.open("letters.txt");//letters.txt file created
        cout<<"Including 'A', how many total letters would you like to store? ";
        cin>>totalLetters;//get input value from user
        for(char ch = 'A'; ch < 'A'+totalLetters; ch++)
                File << ch <<" ";//Write letters to file
        File.close();//Close file
}

C++ PROGRAM SCREENSHOT

OUTPUT SCREENSHOT


Related Solutions

Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
1a) Starting at the level of the external environment, identify the environmental condition and series of...
1a) Starting at the level of the external environment, identify the environmental condition and series of steps that would be required to hyperpolarize an ‘on’ bipolar cell. Assume that the photoreceptor is wired directly to the bipolar cell. 1b) How would the environmental condition and/or series of steps in part 1a) be different (if at all) if you had hyperpolarized an ‘off’ bipolar cell? Again, assume that the photoreceptor is wired directly to the bipolar cell. 1c) In question 1b),...
2. Write a Java program that reads a series of input lines from given file “name.txt”,...
2. Write a Java program that reads a series of input lines from given file “name.txt”, and sorts them into alphabetical order, ignoring the case of words. The program should use the merge sort algorithm so that it efficiently sorts a large file. Contents of names.text Slater, KendallLavery, RyanChandler, Arabella "Babe"Chandler, StuartKane, EricaChandler, Adam JrSlater, ZachMontgomery, JacksonChandler, KrystalMartin, JamesMontgomery, BiancaCortlandt, PalmerDevane, AidanMadden, JoshHayward, DavidLavery,k JonathanSmythe, GreenleeCortlandt, OpalMcDermott, AnnieHenry, DiGrey, MariaEnglish, BrookeKeefer, JuliaMartin, JosephMontgomery, LilyDillon, AmandaColby, LizaStone, Mary FrancesChandler, ColbyFrye, DerekMontgomery,...
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
Write a program that will prompt for a word with at least five letters in it...
Write a program that will prompt for a word with at least five letters in it (if not, keep asking for input). Then evaluate the word to produce a count of all the vowels in the word. Sample output appears below. Enter a word at least 5 characters long:<SPC>cat<ENTER> Enter a word at least 5 characters long:<SPC>dog<ENTER> Enter a word at least 5 characters long:<SPC>concatenate<ENTER> Letter Counts ========= a: 2 e: 2 i: 0 o: 1 u: 0
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
This program will read a bunch of numbers from an external file (numbers.txt) and calculate their...
This program will read a bunch of numbers from an external file (numbers.txt) and calculate their total and average. In addition, the total will be multiplied by an integer that is supplied by the user. ** IMPORTANT: The numbers are included in your starter code as a separate file (numbers.txt). Don't touch that file! All of your code should be placed in code.cpp, as usual. ** Input: After all numbers are read, what number would you like to multiply the...
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT