EE1301_HW4

pdf

School

University of Minnesota-Twin Cities *

*We aren’t endorsed by this school

Course

1301

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

6

Uploaded by KidFishPerson934

Report
EE 1301: Introduction to Computing Systems Homework 4 Purpose Going from operating on user input alone to also retrieving information from files allows our programs to increase substantially in complexity and usefulness. This assignment will require you to read data from a file, process that data, and then output a summary of the results to another file. Some problems involve more complex data formats that will require you to use more complex loops / conditionals as well as larger numbers of variables. Naming your variables intelligently and remaining consistent in your formatting (indentation) can substantially reduce the number of mistakes you make while coding. Recommended Reading (zyBooks) 6.5 File Input 6.7 File Output 3.13 String Access Operations 3.15 More String Operations 6.6 & 6.8 File I/O Examples Libraries You may use the following libraries for this assignment: #include <iostream> #include <iomanip> #include <fstream> #include <string> Problem A: Making the grade (5 points) The file grades.txt contains a list of names with grades, separated by spaces. Note that the grades may contain decimal values. John Watson 43 Sherlock Holmes 92 Violet Crawley 83 Write a program that reads in the grades from “grades.txt” and then outputs the distribution of letter grades to the terminal. Have your program also create an excel-friendly, comma delimited file called “statistics.csv” that contains the grade distribution. The necessary format for both the terminal output and statistics.csv are shown in the examples below. Your program should read in the grade for each person, then determine their letter grade using the breakdown shown here. These grade boundaries are inclusive, so an A is anything >= 90.0.
Grade A B C D F Min % 90 80 70 60 0 Your program should display the distribution of letter grades to the terminal, as shown in the “Example Terminal Output” below and create a similar excel-friendly file called statistics.csv, shown in “Example File Output” below. Make sure to match the format in the examples below exactly . Notice that the format is different between the terminal output and the .csv output, so double check that you are using the correct format for each. Example Terminal Output 3 A 5 B 2 C 1 D 1 F Example File Output (statistics.csv) Grade,NumStudents A,3 B,5 C,2 D,1 F,1 There may be different input files we want to use with your program, so we have also set up a second “ grades.txt #2” file for you to use with different students and grades. Test that your code works for any “grades.txt” file stored in the same directory as your program. Use only one of these files at a time, and make sure the file you are using is named grades.txt. In other words, always have your program look for “grades.txt” in the current directory and move or rename your grades.txt files to determine which one will be used by the program. Note that your program should support reading in any number of students, since the number of students in “grades.txt” is not a set number, but rather depends on the contents of the file. Also, these files will contain both integer grades and floating-point grades, so your program should use a data type that supports reading in grades that are either integer or floating-point numbers. For your final submission, set your input file to point to “grades.txt”, and assume that “grades.txt” will be located in the same directory as your program. Set your program to create an output file named “statistics.csv” in the same directory as your program.
Test Cases This program takes no variable inputs, but you should make sure to test it with several input files with different numbers of grades (e.g., grades.txt #1 and grades.txt #2). We recommend creating at least one more grades.txt file of your own for testing. For your submission, you only need to submit your appropriately named source code (your *.cpp file). You do not need to include any grades.txt file with your submission. Problem B: Grade distribution (5 points) Read in “statistics.csv” (generated in Problem A) and use the statistics to make a “histogram.txt” file that uses Xs to show how many people received each letter grade (example below). For example, if there is a “3” after the “A” in “statistics.csv” then the histogram should show 3 Xs for the “A” category vertically above the A. The first (leftmost) column should show a scale, starting at 1 and going up to the maximum number of Xs for any grade. For example, if B was the most popular grade with 5 occurrences, then the scale should go from 1 to 5 (see example below). Make sure that your program is configured to look for “statistics.csv” in the same directory as your program, [ Hint: The first step in making the proper histogram format would be to figure out how many numbers to print vertically. Then, you can figure out a relationship between each number that will appear on the vertical axis and whether or not there is an X in the column corresponding to each grade.] The only output for this problem is “histogram.txt”, and there will be no output to the terminal. Example File Output (distribution for grades.txt #1) 5 X 4 X 3XX 2XXX 1XXXXX ----- ABCDF
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
E xample File Output (distribution for grades.txt #2) 7 X 6 X 5 X 4XX 3XXX 2XXXX 1XXXXX ----- ABCDF NOTE: You will generate a new statistics.csv each time the program runs. These two examples are the histograms that should be generated corresponding to the two example grades.txt files provided for part A. For your submission, you only need to submit your appropriately named source code (your *.cpp file). You do not need to include any other files with your submission. Problem C: Most Popular Vowel (5 points) Write a program that scans the file “input_files/ blahblah.txt ” and returns the count of ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ in the file (combine occurrences of both upper and lower case letters). Report the count and the winner (the most popular vowel) to the terminal. In case of a tie between two or more vowels, your output should declare one of the vowels for which the tie happened as the winner (it doesn’t matter which one you declare as the winner). Note that your program should be able to handle reading in the contents of any “blahblah.txt” file, so your program should be able to handle files of different lengths. Finally, the program should stream the results out to a file in the directory “output_files/election_results.txt”. Example Terminal Output #1 The results are in! A/a received 227 votes E/e received 315 votes I/i received 330 votes O/o received 129 votes U/u received 268 votes The winner is the letter "I"!
Example File Output #1 A,227 E,315 I,330 O,129 U,268 Example Final Directory Structure and Files for Part C: Your final directory structure should have both the input_files and output_files as directories at the same level as your .cpp file and compiled executable. In other words, you need to create 2 new directories, called input_files and output_files, to store “blahblah.txt” and “election_results.txt”. These directories will be created in your current working directory, and your code for problem C needs to look for the program’s input and output files in the input_files and output_files directories. An example of how the directory structure should look is provided below. . └── hw4_directory/ ├── input_files/ └── blahblah.txt ├── jaco2670_hw4C ├── jaco2670_hw4C.cpp └── output_files/ └── election_results.txt For your submission, you only need to submit your appropriately named source code (your *.cpp file). You do not need to include the input or output directories, blahblah.txt, or election_results.txt. In other words, your program should look for these files in the right location, but you only need to include your source code when you submit. Submission Please submit the following files in Canvas - Gradescope: username _hw4A.cpp username _hw4B.cpp username _hw4C.cpp It is important that you follow the file naming conventions very carefully for efficiency in grading homework. (You want your homework returned before the final, right?). Please note that the auto-grader will not compile your submission if it is named incorrectly. Please also note the following: Your username should be all in lowercase You should not include “@umn.edu”
The filename should contain an underscore (not a dash) The ‘A’ in “4A” is upper case The extension for your source files is .cpp Following rigorous naming conventions is something computer programmers often must do, and submitting your program with the correct name is part of doing this assignment correctly. Grading As in Homework 1, all submissions should be in the form of a source file that compiles without error and executes correctly on the CSE Linux machines / Gradescope. This assignment will be graded as follows. Problem A - 15pts Autograder: (1 pt) Output File - statistics.csv in the same directory (6 pts) Contents of statistics.csv - Header, Count of students (2 pts) User interface (I/O formatting) Manual Grading (3 pts) File Handling - Open, Check if open, Close (3 pts) Coding Style - readability, header, and comments with your name, etc. Problem B - 13pts Autograder: (1 pt) Output File - histogram.txt in the same directory Manual Grading (6 pts) Histogram Formatting (3 pts) File Handling - Open, Check if open, Close (3 pts) Coding Style - readability, header, and comments with your name, etc. Problem C - 17pts Autograder (2 pts) Output File - election_results.txt in the output_files/ directory (5 pts) Contents of election_results.txt - Count of vowels (1 pt) Winner (2 pts) User interface (I/O formatting) Manual Grading (4 pts) File Handling - Open, Check if open, Close (3 pts) Coding Style - readability, header, and comments with your name, etc.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help