Alright, after about a good 10 hours of messing around with this, I figured it wouldn't hurt to ask for some help. I have very little experience coding as this is my first semester in school as a computer science guy. We are using the language C++. The problem revolves around using function decomposition to take numbers from an inputfile and printing them out using asterisks.
Here are the instructions:
You will be writing a program that will read 4-digit numbers from a file and writes each of them to another file as block numbers. As an example, the provided file numbers.txt contains three numbers:
1234
5678
9067
The program will write out the following:
********** ********** ********** **********
** ** ** ** **
** ** ** ** **
** ** ** ** **
********** ********** ** **********
** ** ** ** ** **
** ** ** ** ** **
** ** ** ** ** **
** ** ** ** ** **
********** ********** ** **********
Their a little botched. For some reason they get formatted differently once I paste them in here.
Each of these block numbers is 10 (width) x 10 (height/lines) characters (including spaces).
An additional space is added after each line of a digit to separate it from the next.
Two new lines are used to separate one of the 4-digit numbers from the next.
To practice good function decomposition, you will be required to write 12 functions for this project:
1 for each of the 10 digits 0–9 (ten total functions).
These functions will take a std::ifstream and a line number.
Each will use an array of 10 std::string (1 for each line) to store the digit.
Each call to one of these functions will write out one line of a digit.
1 function that writes out a single 4-digit number
This function will take the std::ofstream and the 4-digit number to write out
You will need to use / and % to get each digit from the 4-digit number. Using 1234 as an example, the following gets each digit:
1st digit (1): (1234 / 1000) % 10
2nd digit (2): (1234 / 100) % 10
3rd digit (3): (1234 / 10) % 10
4th digit (4): (1234 / 1) % 10
This function will write out each digit of the 4-digit number line by line using the previous 10 functions. First, it will write out the 1st line of all four digits, then 2nd, etc.
A function that reads each of the numbers one at a time from the ifstream and writes the 4-digit number via a call to the function that writes a single 4-digit number
Im having an extremely difficult time with the first ten functions for each of the ten digits. This is the code I currently have... I've tried using different return types and structuring the function many ways yet none seem even close to working properly.
First of all, your display_zero function does NOT need to print out the value to standard out (Although perhaps you are doing this to test if it displays properly, in which case it is fine).
Also, I think your instructor may be mistaken here:
Each call to one of these functions will write out one line of a digit.
He/she then instructs that the functions should take an std::ifstream. ifstreams are used for input, not output. Thus, the correct method is to use an std::ofstream. In this example, I use an ostream instead of an ofstream, so I can use std::cout to test it. You can either keep it as ostream or use ofstream instead and pass a filestream.
By the way, you don't need your zero() function to return anything, just make it void. All it is doing is outputting to the filestream.
Also, please use code tags when writing code on this website. You can do so by clicking the button that looks like "< >" and write your code in it so it is formatted correctly.