In C++ please! I've included header and makefile.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

In C++ please! I've included header and makefile.

Post by answerhappygod »

In C++ please! I've included header and makefile.
In C Please I Ve Included Header And Makefile 1
In C Please I Ve Included Header And Makefile 1 (84.85 KiB) Viewed 62 times
In C Please I Ve Included Header And Makefile 2
In C Please I Ve Included Header And Makefile 2 (144.49 KiB) Viewed 62 times
In C Please I Ve Included Header And Makefile 3
In C Please I Ve Included Header And Makefile 3 (52.46 KiB) Viewed 62 times
In C Please I Ve Included Header And Makefile 4
In C Please I Ve Included Header And Makefile 4 (40.32 KiB) Viewed 62 times
In C Please I Ve Included Header And Makefile 5
In C Please I Ve Included Header And Makefile 5 (46.65 KiB) Viewed 62 times
F or faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the zip code: CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE ECRLOT ** C057 CA 95014-5143 Hladıdll....llıdakıll.lllabollbald The encoding scheme for a five-digit zip code is shown below. • There are full-height frame bars on each side. • The five encoded digits are followed by a check digit, which is computed by add- ing up all digits, and choose a check digit to make the sum a multiple of 10. Frame bars CO57 • For example, the number 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20. ...... ..... ..... ..... ..... Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 ...... Check Digit Encoding for Five-Digit Bar Codes
Each digit of the zip code, and the check digit, is encoded according to the following table where O denotes a half bar and 1 a full bar. Digit 1 2 3 4 5 6 7 8 9 Bar 1 Bar 2 (weight 7) (weight 4) 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 Bar 3 (weight 2) 0 1 1 0 0 1 0 0 1 Bar 5 Bar 4 (weight 1) (weight 0) 1 0 1 O 1 0 0 1 0 1 0 1 0 0 1 0 0 To solve this problem, write three functions (pay attention to the return types): • string codeForDigit(int digit) which takes one digit and returns the ap- propriate code for that digit, using the table above. Use: for the half-bars and '|' for the full bars. zip) which calculates the check digit according to the • int checkDigit(int rules shown above. • string barCode(int zip) which returns an entire bar code by breaking the number into individual digits, encoding that digit, and adding it to the string re- turn value. Finally, calculate and encode the check digit, surround the entire code with the frame bars, and return it. Here are the steps to solve this problem: 1. Write and document the prototypes the header file. Add header guards. 2. Stub out your functions in the implementation file. Run make test to make sure you have the mechanics correct before going on. 3. Implement the codeForDigit() function first. Run the tests for that. 4. Calculate the checkDigit() function and run the tests for that. 5. Finally, write and test the barCode() function (which will be fairly short).
A Few Hints • codeForDigit() works great with just a switch. • For checkDigit(), use a limit loop as well as the remainder operator to find the digit that gets the sum to the next multiple of 10. • For barCode(), first calculate the check digit. Extract each digit using a limit loop and get its code; use the building-a-string pattern to add the code to the result. Finally, add the code for the check digit and the two frame bars. Use make test to test your code or make run to run any student tests. Once your score is OK, use make submit to turn it in.
h08.cpp h08.h X makefile 1 /// Put the interface to the bar-code libary here 2 #ifndef H08_H_ 3 #define H08_H_ 4 /** 5 ..@file h08.h @author 6 7 */ 8 9 #include <string> 10 /** 11 ...Computes a barcode given a 5-digit zip code. @param zip the 5-digit zip code. 12 13 14 */ 15 std::string barCode(int zip); 16 @return the bar code with | for full bars and : for half bars. * 17 /* 18 19 20 21 */ 22 std::string codeForDigit(int digit); 23 24 /** · Returns the bar code value for a given digit. @param digit integer @return string encoding of the digit 25 .* Calculates the check digit for a zip code. 26 @param zip the zip code 27 * @return_check digit for zip according to this rule. 28 * 29 .* Sum all the digits in the zip code. 30 */ 31 int checkDigit(int zip); 32 33 #endif 34
h08.cpp 1 EXE = h08 2 CXX = @g++ 3 CXXFLAGS = -std=c++17 -Wall - Wextra -Werror -00 -ggdb3 -fsanitize-signed-integer-overflow -fsanitize=undefined -Wno-unused-parameter -Wno-unused-variable -Wshadow 4 LIBS = $(EXE) 5 SRC = $(EXE).cpp 6 OBJS = $(EXE).O 7 8 $(EXE): $(OBJS) makefile 9 → $(CXX) $(CXXFLAGS) -o $@ $(OBJS) -L./ -1$ (LIBS) h08.h 10 11 # Remove object files from folder 12 clean: 13 → rm -f core $(EXE) *.0 14 15 lint: 16 → clang++ --analyze -Xanalyzer -analyzer-output=text $(EXE).cpp 17 18 run: $(EXE) 19 → ./$(EXE) 20 21 test: $(EXE) 22 → ./$(EXE) -t makefile x 23 24 submit: $(EXE) 25 → 26 → 27 → 28 @./$(EXE) -t 1> /dev/null 2> results.txt; true @curl `cat /workspaces/$(RepositoryName)/.submit.txt``tail -n 1 results.txt` https://cs170-console.appspot.com/update; true @rm -rf errors.txt 2> /dev/null; true
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply