In: Computer Science
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
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