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)...
Write a program that reads from the external file input.txt, capitalizes all words that begin with...
Write a program that reads from the external file input.txt, capitalizes all words that begin with the letter "a," and then writes them to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Output: After the program generates output.txt, the code should display the contents of the file on the screen to verification.
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,...
External sort: Write an external merge sort in c++ that takes in an input file with...
External sort: Write an external merge sort in c++ that takes in an input file with 120 integers. You are allowed to hold a maximum of 20 integers in memory. You must create 2 files to process the integers and they must be sorted and placed in the original file.
Write a program that copies the contents of one file to a destination file. This program...
Write a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Be sure to include all necessary error checking, including ensuring that the source file exists. Also, if available, you have to use Linux system calls and not standard C library functions in your program. Write/type your source code in your submission file/document. [Restrictions] For file handling operations, only use...
Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file...
Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file for the following problem: Input: a number, n, using prompt, which is the number of the factorial numbers to be displayed. Output: a bordered table of numbers with proper caption and headings in which the first column displays the numbers from 1 to n and the second column displays the first n factorial numbers. For example, if a user enters 10 to be the...
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
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT