Hit The Order Button To Order A **Custom Paper**

>> CLICK HERE TO ORDER 100% ORIGINAL PAPERS FROM AustralianExpertWriters.com <<

4 Feb
2020

Starting Computing AssignmentTutorOnline | Good Grade Guarantee!

CSCI 1300 CS1: Starting ComputingInstructor: Fleming/Wong, Spring 2019Homework 6Due Monday, March 4, by 6 pm+5% bonus if submitted by Sunday, March 3, 11:59 pm**The work you do in this assignment will be used as part of the upcomingassignments and project 2.All 3 components (Cloud9 workspace, Moodle CodeRunner attempts, and zip file) mustbe completed and submitted by Monday, March 4, by 6 pm for your homework toreceive points.
Objectives? Array operations: initialization, search? Improve proficiency with loops and strings? Use filestream objects to read data from text files? Get started with part of your Project 2
Submission RequirementsAll three steps must be fully completed by the submission deadline for your homework tobe graded.
Create Hmwk6 directory on your Cloud 9 workspace: Your recitation TA willreview your code by going to your Cloud9 workspace. TAs will check the last versionthat was saved before the submission deadline.? Create a directory called Hmwk6 and place all your file(s) for this assignmentin this directory.? Make sure to save the final version of your code (File > Save). Verify that thisversion displays correctly by going to File > File Version History.? The file(s) should have all of your functions, test cases for the functions inmain() function(s), and adhere to the style guide. Please read thesubmission file instructions under Week 4.
Submit to the Moodle CodeRunner: Head over to Moodle to the link Homework 6CodeRunner. You will find one programming quiz question for each problem in theassignment. Submit your solution for the first problem and press the Check button.You will see a report on how your solution passed the tests, and the resulting scorefor the first problem. You can modify your code and re-submit (press Check again)as many times as you need to, up until the assignment due date. Continue with therest of the problems.
Submit a .zip file to Moodle: After you have completed all 9 questions from theMoodle assignment, zip all 9 files you compiled in Cloud9 (one cpp file for eachproblem), and submit the zip file through the Homework 6 (File Submission) linkon Moodle.
RubricAside from the points received from the Homework 6 CodeRunner quiz problems, your TAwill look at your solution files (zipped together) as submitted through the Homework 6 (FileSubmission) link on Moodle and assign points for the following:Style and Comments (5 points):? The style guide is posted on Moodle under week 6.? Your code should be well-commented. Please review the standard forwell-commented code, presented in more detail in previous homework write-ups.? Please also include a comment at the top of your solution with the following format:// CS1300 Spring 2019// Author: my name// Recitation: 123 – Favorite TA// Cloud9 Workspace Editor Link: https://ide.c9.io/…// Homework 6 – Problem # …Global variables (use will attract a 5 points deduction):? Later in the semester, we will learn about global variables and the joys anddangerous therein. To keep things simple, straightforward, and easy to debug andtest, you may not use global variables in this homework.Algorithm (5 points):? Before each function that you define, you should include a comment that describesthe inputs and outputs of your function and what algorithms you are using inside thefunction. Please review the standard for including your algorithm for each function,presented in more detail in previous homework write-ups.Test Cases (20 points):
Code compiles and runs (6 points):? The zip file you submit to Moodle should contain 9 full programs (each with amain() function), saved as .cpp files. It is important that your programs canbe compiled and run on Cloud9 with no errors. The functions included inthese programs should match those submitted to the CodeRunner on Moodle.
Test cases (14 points):For this week’s homework, 7 problems are asking you to create a function (Problems2 through 8). In your Cloud9 solution file for each function, you should have 2 testcases present in their respective main() function, for a total of 14 test cases (seethe diagram on the next page). Your test cases should follow the guidelines, WritingTest Cases, posted on Moodle under Week 3.Please make sure that your submission files follow the the submission fileinstructions under Week 6.
Part One: Syntax4.1. Background4.1.1. ArraysAn array is a data structure which can store primitive data types like floats, ints, strings,chars, and booleans.Arrays have both a type and a size.? How to Declare Arraysdata_type array_name[declared_size];bool myBooleans[10];string myStrings[15];int myInts[7];? How to Initialize Arrays (Method 1)bool myBooleans[4] = true, false, true, true;If you do not declare the size inside the square brackets, the array size will be setto however many entries you provide on the right.bool myBooleans[] = true, false, true; // size = 3Note: the size specified in the brackets needs to match the number of elementsyou wrote in the curly brackets.Example 1: When the specified size is larger than the actual number of elements,the elements provided in the curly brackets will be the first several elements inthe array, while the additional elements will be filled with default values. If it’s aninteger/double array, the default values are zero, while if it’s a string array, thedefault values are empty strings.

AssignmentTutorOnline
using namespace std;int main()int intArray[5] = 1,2,3;for (int i = 0; icout}Output:1 2 3 0 0Example 2: When the specified size is smaller than the actual number ofelements, there will be a compilation error.

using namespace std;int main()int intArray[3] =1,2,3,4,5;Output (Error message):error: excess elements in arrayinitializerint intArray[3] = 1,2,3,4,5;^1 error generated.? How to Initialize Arrays (Method 2)You can also initialize elements one by one using a for or while loop:int myInts[10];int i = 0;while (imyInts[i] = i;i++;}//0, 1, 2, 3, 4, 5, 6, 7, 8, 9? How to Access Elements in an ArrayWe have essentially already had practice with accessing elements inarrays, as in C++, strings are arrays of characters.You can access elements in arrays using the same syntax you used forstrings:string greetings[] = “hello”, “hi”, “hey”, “what’s up?”;cout“hello” “hi” “hey” “What’s up?”0 1 2 3Arrays can be iterated in the same way we iterated over strings last week. Belowwe are iterating through an array of strings:string greetings[] = “hello”, “hi”,“hey”, “what’s up?”;int size = 4;int i = 0;while (icouti++;}Output:hellohiheywhat’s up?4.1.2 Two-dimensional ArraysTwo-dimensional arrays are also arrays, but they are arrays of arrays. When youdeclare a one-dimensional array of integers, it will look like this:int integer_array[10];To declare a two-dimensional array, simply add a new dimension as follows,int integer_array[10][20];which will create a 10 x 20 matrix. The (i, j) element of this matrix is accessed byinteger_array[i][j];Initializing values for two-dimensional arrays is similar to the one-dimension case. Forexample, if you want to initialize a two-dimensional array with some values, here’s whatyou might want to do:int integer_array[2][2] = 10, 20, 30, 40 ;However, be careful when you write something like this,int integer_array[2][2] = 10, 20 ;which does not give the matrix as10 2010 20Instead, it gives you10 200 0This is similar to the example 1 in Method 1 of initializing arrays (see here). Because thesecond dimension is specified as 2, but we only provide the array in the first dimension,i.e., 10,20, the second array is filled with default values.4.1.3. Passing arrays to functions? Passing By ValueUp until now, when calling functions, we have always passed by value. When aparameter is passed in a function call, a new variable is declared and initializedto the value passed in the function call.Observe that the variable x in main and variable x in addOne are separatevariables in memory. When addOne is called with x on line 9, it is the value of x(i.e. 5) that is passed to the function. This value is used to initialize a newvariable x that exists only in addOne’s scope. Thus the value of the variable x inmain’s scope remains unchanged even after the function addOne has beencalled.1234567891011void addOne(int x)x = x + 1;coutint main()int x = 5;coutaddOne(x);coutOutput:565? Passing By ReferenceArrays, on the other hand, are passed by reference (to the original array’slocation in the computer’s memory. So, when an array is passed as a parameter,the original array is used by the function.Observe that there is only one array X in memory for the following example.When the function addOne is called on line 9, a reference to the original array Xis passed to addOne. Because the array X is passed by reference, anymodifications done to X in addOne are done to the original array. Thesemodifications persist and are visible even after the flow of control has exited thefunction and we return to main.12345678910void addOne(int X[])X[0] = X[0] + 1;coutint main()int X[4] = 1, 5, 3, 2;coutaddOne(X);coutOutput:122When we pass a one-dimensional array as an argument to a function we also provideits length. For two-dimensional arrays, in addition to providing the length (or number ofrows), we will also assume that we know the length of each of the subarrays (or thenumber of columns). A function taking a two-dimensional array with 10 columns as anargument then might look something like this:void twoDimensionalFunction(int matrix[][10], int rows) …4.1.4 File Input/OutputDuring this class so far, we have been using the iostream standard library. This libraryprovided us with methods like cout and cin. cin is a method is for reading from standardinput (i.e. in the terminal via a keyboard) and cout is for writing to standard output.In this part, we will discuss file input and output, which will allow you to read from andwrite to a file. In order to use these methods, we will need to use another C++ standardlibrary, fstream (file stream).These headers must be included in your C++ file before you are able to process files.

Reading lines from a file:To read lines from a file, you need to take the following steps.Step 1: Make a stream object. Create an object (a variable) of file stream type. If youwant to open a file for reading only, then the ifstream object should be used (“input filestream”).Example://create an output file stream for writing to fileifstream myfile;Step 2: Open a file. Once you have an object (a variable) of file stream type, you needto open the file. To open the file, you use the method (function) named open. Forifstream objects, the method takes only one parameter: the file name as a string(surrounded by “ “ if giving file name directly)Example://open the file file1.txt with the file streammyfile.open(“file1.txt”);Step 3: Checking for opening file. It is always good practice to check if the file hasbeen opened properly and send a message if it did not open properly. To check if a filestream successfully opened the file, you can use fileStreamObject.is_open().This method will return a Boolean value true if the file has successfully opened andfalse otherwise.Example:if (myfile.is_open())// do things with the fileelsecoutStep 4: Read lines from the files. To read a line from the file, you can usegetline(filestream, line) which returns true as long as an additional line hasbeen successfully assigned to the variable line. Once no more lines can be read in,getline returns false. So we can set up a while loop where the condition is the call togetline.Example:string line = “”;int lineidx = 0;// read each line from the filewhile (getline(myfile, line))// print each line read from the filecout// increment index(count of lines in the file)Lineidx++;Step 5: Closing a file. When you are finished processing your files, it is recommendedto close all the opened files before the program is terminated. The standard syntax forclosing your file is myfilestream.close();Example:// closing the filemyfile.close();Step 6: Putting it all together. Here is the temple for reading lines from a file//create an output file stream for writing to fileifstream myfile;//open the file file1.txt with the file streammyfile.open(“file1.txt”);if (myfile.is_open())// do things with the filestring line = “”;int lineidx = 0;// read each line from the filewhile (getline(myfile, line))// print each line read from the filecout// increment index(count of lines in the file)Lineidx++;elsecout// closing the filemyfile.close();? Other functionsHere are some useful functions for this week’s assignment. We’ve provided linksto documentation on how to use them. These pages provide explanation on thefunction as well as examples on how to use them:? string.length() (find the length of a string)? string.empty() (determine if a string is empty or not)? getline (extract characters from a stream and place into a string)? fstream::open (open a file)? fstream::is_open (determine if a file successfully opened)? ios::fail (determine if a file successfully opened)? ios::eof (determine if at the end of a file)? stoi (convert string to integer)? stod (convert string to double)
Problem SetNote: To stay on track for the week, we recommend to finish/make considerableprogress on Problems 1-4 by Wednesday. Students with recitation on Thursdayare encouraged to come to recitation with questions and have made a start on allof the problems.The first 4 problems are to get some practice working with arrays. You will turn in aseparate .cpp file for each of the first 4 problems. The remaining 5 problems are to get arunning start on Project 2, wherein we will develop a book recommendation system(description below). You will turn in a version of the function that is tested in its ownprogram, as well as one single .cpp program that includes all of Problems 5-9. All 9problems are required. Note however that there are still separate Coderunner problemson Moodle for testing your codes.5.1. Underhand tossesProblem 1 (5 points) arrayPilgrimageWrite a program arrayPilgrimage.cpp to declare and populate the four arrayslisted below. For testing in Coderunner, you will paste the main() function from yourprogram.? temps – an array of 10 floating point numbers initialized with -459.67 (absolutezero in Fahrenheit)? colors – an array of the strings “Red”, “Blue”, “Green”, “Cyan”, and “Magenta”,in that order.? sequence – an array of the first 100 positive integers in order; 1, 2, 3, 4, … etc.? letters – an array of all uppercase and lowercase characters in order, A, a, B,b, C, c, … Hint: the ASCII table will be helpful here!In order to test that you correctly created and populated the arrays, print the values ofeach of their elements, in order, one element per line. Hint: use a loop to traverse eacharray.Expected output:-459.67-459.67…-459.67RedBlue…Magenta12…100A aB b…Z zIn Cloud9 the file should be called arrayPilgrimage.cpp and it will be one of 9 files youneed to zip together for the Homework 6 (File Submission) on Moodle.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem1, in the Answer Box, paste the entire program. Press the Check button. You canmodify your code and re-submit (press Check again) as many times as you need to.Problem 2 (10 points) floodMapWrite a function floodMap which accepts three input arguments, in this order: (1) atwo-dimensional array of double. Each element of the array indicates the height of theterrain at a particular point (assume that there are 4 columns). (2) An integer indicatingthe number of rows in the map, and (3) a double indicating the current water level. Thefunction should print out a “map” of which points in the array are below the water level.In particular, each position at or below the water level will be represented with a * andeach position above the water level will be represented with an underscore . ? Your function should be named floodMap ? Your function should take three parameters, in this order: ? a two-dimensional array of double with 4 columns, ? the integer number of rows in the array, and ? a double indicating the current water level. ? Your function should print a flood map as described below. ? Your function should not return anything Examples: Function call Output double map[1][4] = 5.0, 7.6, 3.1, 292; floodMap(map, 1, 6.0); _double map[2][4] = 0.2, 0.8, 0.8, 0.2,0.2, 0.2, 0.8, 0.5;floodMap(map, 2, 0.0);
double map[2][4] = 0.2, 0.8, 0.8, 0.2,0.2, 0.2, 0.8, 0.5;floodMap(map, 2, 0.5);_*double map[2][4] = 0.2, 0.8, 0.8, 0.2,0.2, 0.2, 0.8, 0.5;floodMap(map, 2, 1.0);
double map[4][4] = 1.0, 5.0, 1.0, 1.0,1.0, 5.0, 5.0, 1.0,5.0, 1.0, 5.0, 5.0,1.0, 1.0, 1.0, 1.0;floodMap(map, 4, 3.14);**
In Cloud9 the file should be called floodMap.cpp and it will be one of 9 files you needto zip together for the Homework 6 (File Submission) on Moodle.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem2, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 3 (10 points) splitThe split function from Homework 5 was such a blast, let’s do it again, but with an arraythis time! Write a new function split which takes four input arguments: a string to besplit, a character to split on (“a delimiter”), an array of strings to fill with the split piecesof the input string, and an integer representing the maximum number of split stringpieces. The function will split the input string in to pieces separated by the delimiter, andpopulate the array of strings with the split pieces up to the provided maximum numberof pieces. Your function will return the number of pieces the string was split into.? Your function should be named split? Your function takes four input arguments:? The string to be split.? A delimiter character, which marks where the above string should be splitup.? An array of string, which you will use to store the split-apart string pieces.? The int length of the given array? Your function returns the number of pieces the input string was split into as aninteger.? Your function does not print anything.? If the input string is split into more pieces than the array of string can hold (morethan the indicated length), your function should fill only as many words as it can,and return -1.? Note: On Sunday Feb 24, the solution to the split() function from Homework 5will be posted.Example: in the following examples, printArray function will output all the elementsin the array, one per line.Function calls Outputstring words[6];coutprintArray(words);3onesmallstepstring words[6];coutprintArray(words);3onesmallstepstring words[6];coutprintArray(words);3cowbig pigfishstring words[6];coutprintArray(words);3cowbig pigfishstring words[6];coutprintArray(words);5uitetioallystring words[2];coutprintArray(words);-1onesmallIn Cloud9 the file should be called split.cpp and it will be one of 9 files you need to ziptogether for the Homework 6 (File Submission) on Moodle.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem3, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 4 (15 points) getLinesFromFileWrite a function called getLinesFromFile that reads from a text file and stores itscontents in an array. Each line in the file will either contain a single integer or be empty.? Your function should be named getLinesFromFile? Your function should take three parameters in the following order:? A string fileName? An array of integers int arr[]? The int length of the given array? Your function will open and read the file specified by the fileName parameter.This string should include both the name and extension of the file (what type offile it is). There are some good and bad examples below:? Good: “books.txt”? Bad: “authors”? Your function should read the file line by line, and at each line if there is anumber it should store it in the array specified by the arr[] parameter.? If a line is empty it should continue reading until it sees another integer beforeadding to the array. Empty lines should not be added to the array.? Once the array is full (length integers have been added), subsequent integers inthe file should be ignored.? If your function has added any integers to the array (meaning that the specifiedfile exists and could be read), it should return the number of integers added tothe array.? If the file does not exist, return -1.? Your function does not print anythingExample:fileName.txt 152318Function call int arr[4];coutprintArray(arr);Output 4152318Value of arr 1, 5, 23, 18In Cloud9 the file should be called getLinesFromFile.cpp and it will be one of 9 filesyou need to zip together for the Homework 6 (File Submission) on Moodle.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem4, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.5.2. Part Two: Fast-pitch this timeIf you’ve ever bought a book online, the bookseller’s website probably told you whatother books you might like. This is handy for customers, but also very important forbusiness. In September 2009, online movie-rental company Netflix awarded one milliondollars to the winners of the Netflix Prize. The competition simply asked for an algorithmthat would perform 10% better than their own algorithm. Making good predictions aboutpeople’s preferences was that important to this company. It is also a very current area ofresearch in machine learning, which is part of the area of computer science calledartificial intelligence.So how might we write a program to make recommendations for books?Consider a user named Rabia. Rabia loves a good book! How can we write programthat can predict books she that might like?The simplest approach would be to simply calculate the average rating for all of thebooks in the database, sort the books by rating and then from that sorted list, suggestthe top 5 books that Rabia hasn’t already rated. In this case, the program would makealmost the same prediction for every customer. With this simple approach, the onlyinformation unique to Rabia used by the prediction algorithm was whether or not Rabiahad read a specific book.We could make a better prediction about what Rabia might like by considering heractual ratings in the past and how these ratings compare to the ratings given by othercustomers. Consider how you decide on movie recommendations from friends. If afriend tells you about a number of movies that s(he) enjoyed and you also enjoyedthem, then when your friend recommends another movie that you have never seen, youprobably are willing to go see it. On the other hand, if you and a different friend alwaystend to disagree about movies, you are not likely to go to see a movie that this friendrecommends.A program can calculate how similar two users are by treating each of their ratings as aarray/vector and calculating a similarity score based on some calculation (like a dotproduct, or a sum of squared differences) using the two arrays.Once you have calculated the pair-wise similarity between Rabia and every othercustomer, you can then identify whose ratings are most similar to Rabia’s. If anotheruser, Suelyn, is most similar to Rabia, we would recommend to Rabia the top booksfrom Suelyn’s list that Rabia hadn’t already rated.Your task for this preliminary part of Project 2 is to develop logistical methods forinitializing the database and manipulating its contents. In upcoming assignments, youwill exploit these operations for making recommendations.Problems leading up to Project 2For each of Problems 5-8, you will turn in a version of the function that is tested in its ownprogram, as well as all together in Problem 9. Problem 9 builds off of a template HW6.cppprogram (provided on Moodle), which will include your functions from Problems 5-8.Problem 5 (20 points) readBooksWrite a function readBooks that populates a pair of arrays with the titles and authorsfound in books.txt. This function should:? Accept five input arguments in this order:? string fileName: the name of the file to be read.? Array of string: titles.? Array of string: authors.? int numBookStored: the number of books currently stored in the arrays.You can always assume this is the correct number of actual elements inthe arrays.? int size: capacity of the authors/titles arrays. This number shouldalways be greater or equal to the number of books currently stored in thearrays.? Use ifstream and getline to read data from the file, placing author names in theauthors array and titles in the titles array.? You can use the split() function from Problem 3, with comma (‘,’) as thedelimiter. When you copy your code to the coderunner, make sure you put in theanswer box both functions readBooks and split.? Special cases to consider:? When the file is not opened successfully, return -1.? When numBookStored is equal to the size, return -2.? When numBookStored is smaller than size, keep the existing elementsin titles and authors, then read data from file and add the data to thearray. The number of books stored in the array cannot exceed to the sizeof the array.? Empty lines should not be added to the arrays.Example 1: The authors and titles arrays are empty, so numBookStored is zero.fileName.txt Author A,Book 1Author B,Book 2Function call string authors[10] = ;string titles[10] = ;readBooks(“fileName.txt”,titles,authors, 0, 10);Return value 2Value ofauthors“Author A”, “Author B”Value of titles “Book 1”, “Book 2”Example 2: There’s already one book and one author in the arrays, so the data readfrom the file will be added to the array.fileName.txt Author A,Book 1Author B,Book 2Function call string authors[10] = “Author Z”;string titles[10] = “Book N”;readBooks(“fileName.txt”,titles,authors, 1, 10);Return value 3Value of authors “Author Z”, “Author A”, “Author B”Value of titles “Book N”, “Book 1”, “Book 2”Example 3: There’s already one book and one author in the arrays, sonumBookStored is one. However, the array size is only two, so only the first line of thefile is stored.fileName.txt Author A,Book 1Author B,Book 2Author C,Book 3Function call string authors[2] = “Author Z”;string titles[2] = “Book N”;readBooks(“fileName.txt”, titles, authors, 1, 2);Return value 2Value of authors “Author Z”, “Author A”Value of titles “Book N”, “Book 1”Example 4: file does not exist.Function call string authors[2] = “Author Z”;string titles[2] = “Book N”;readBooks(“badFileName.txt”,titles,authors, 1, 2);Return value -1Value ofauthors“Author Z”Value of titles “Book N”Example 5: numBookStored equals size means the array is already full.fileName.txt Author A,Book 1Author B,Book 2Author C,Book 3Function call string authors[1] = “Author Z”;string titles[1] = “Book N”;readBooks(“fileName.txt”, titles, authors, 1, 1);Return value -2Value ofauthors“Author Z”Value of titles “Book N”In Cloud9 the file should be called readBooks.cpp and it will be one of 9 files you needto zip together for the Homework 6 (File Submission) on Moodle. After developing inCloud9, this function will be one of the functions needed at the top of HW6.cpp.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem5, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 6 (15 points) printAllBooksIt will be useful to display the contents of your library. Next, make a functionprintAllBooks that meets the following criteria:? Accept three arguments in this order:? Array of string: titles? Array of string: authors? int: number of books? This function does not return anything? If the number of books is 0, print “No books are stored”? Otherwise, print “Here is a list of books” and then each book in a newline using the following statementcoutNote: In the test case, you can always assume that the number of books matches thenumber of elements in the title array and author array.Expected output (assuming you have read the data from books.txt)Here is a list of booksThe Hitchhiker’s Guide To The Galaxy by Douglas AdamsWatership Down by Richard AdamsThe Five People You Meet in Heaven by Mitch AlbomSpeak by Laurie Halse Anderson…In Cloud9 the file should be called printAllBooks.cpp and it will be one of 9 files youneed to zip together for the Homework 6 (File Submission) on Moodle. Afterdeveloping in Cloud9, this function will be one of the functions needed at the top ofHW6.cpp.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem6, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 7 (30 points) readRatingsWrite a function readRatings that loads user ratings by reading the ratings.txt file.The first value of each line in ratings.txt is the username. Each username isfollowed by a list of ratings of the user for each book in books.txt.For example let us say there are in total 3 books. The ratings.txt file would be ofthe format:ratings.txtritchie,3,3,3stroustrup,0,4,5gosling,2,2,3rossum,5,5,5…Rating Meaning0 Did not read1 Hell no – hate it!!2 Don’t like it.3 Meh – neither hot nor cold4 Liked it!5 Mind blown – Loved it!Your function should:? Accept six arguments in this order:? string: the name of the file to be read? Array of string: users? 2 dimensional int array: ratings – list of ratings for each user.Thenumber of rows corresponds to the number of users, and the number ofcolumns corresponds to the number of books.? int: numUsers number of users currently stored in the arrays? int: maxRows maximum number of rows of the ratings 2D array(convention: array[row][column]) [assume to be 100]? int: maxColumns maximum number of columns of the ratings 2D array
[assume to be 50]
? Use ifstream and getline to read data from the file, placing each usernamein the users array, and each set of ratings in a row of the ratings 2D array.? Hint: You can use the split() – function from problem 3, with comma (“,”) asthe delimiter. When you copy your code in the answer box on MoodleCoderunner, make sure you put both the functions readRatings and split.? You can use stoi to convert each rating value (a string, as read from the textfile) into an integer value.? The function should return the following values depending on cases:? Return the total number of users in the system, as an integer.? If the file cannot be opened, return -1? When numUsers is equal to the maximum number of rows in theratings 2D array, return -2? When numUsers is smaller than the maximum number of rows in theratings 2D array, keep the existing elements in users array andratings array, then read data from file and add (append) the data to thearrays. The number of users stored in the arrays cannot exceed the sizeof the arrays.? Empty lines should not be added to the arrays.Example 1: The users and ratings arrays are empty, so numUsers is 0.ratings.txt Ninja,0,1,2,3,4Myth,2,2,4,5,1Sphyer,3,1,0,0,5Daequan,0,0,0,0,2Function call string users[10] = ;int ratings[10][50] = 0;int numUsers = 0;int maxRows = 10;int maxColumns = 50;readRatings(“ratings.txt”, users, ratings,numUsers, maxRows, maxColumns);Return value 4Value of users “Ninja”, “Myth”, “Sphyer”, “Daequan”, “”, “”,“”, “”, “”, “”Value of ratings0, 1, 2, 3, 4, …, 0, 0,2, 2, 4, 5, 6, …, 0, 0,3, 1, 0, 0, 5, …, 0, 0,0, 0, 0, 0, 2, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,0, 0, 0, 0, 0, …, 0, 0,Example 2: The authors and titles arrays are empty, so numBookStored is 0 anda bad file is givenFunction call string users[] = ;int ratings[10][50] = 0;int numUsers = 0;int maxRows = 10;int maxColumns = 50;readRatings(“badFile.txt”, users, ratings, numUsers,maxRows, maxColumns);Return value -1Value of users “”, “”, “”, “”, “”, “”, “”, “”, “”, “”Value of ratings0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,0, 0, …, 0, 0,Example 3: The users and ratings arrays are full, so readRatings returns -2.moreRatings.txt alpha,0,1,2,3,4beta,0,1,2,3,4gamma,0,1,2,3,4delta,0,1,2,3,4Function call string users[4] = “Ninja”, “Myth”, “Sphyer”,“Daequan”;int ratings[4][50] = 0, 1, 2, 3, 4, …, 0, 0,2, 2, 4, 5, 6, …, 0, 0,3, 1, 0, 0, 5, …, 0, 0,0, 0, 0, 0, 2, …, 0, 0;int numUsers = 4;int maxRows = 4;int maxColumns = 50;readRatings(“moreRatings.txt”,users, ratings, numUsers,maxRows, maxColumns);Return value -2Value of users “Ninja”, “Myth”, “Sphyer”, “Daequan”Value of ratings0, 1, 2, 3, 4, …, 0, 0,2, 2, 4, 5, 6, …, 0, 0,3, 1, 0, 0, 5, …, 0, 0,0, 0, 0, 0, 2, …, 0, 0Example 4: There is already 1 user in the users array, so the value of numUsers is 1.However, the array size is only two, so only the first line of the file is stored and thefunction returns the size of the array.ratings.txt stroustrup,0,4,5gosling,2,2,3rossum,5,5,5Function call string users[2] = “ritchie”;int ratings[2][50] = 0, 1, 2, 0, 0, …, 0, 00, 0, 0, 0, 0, …, 0, 0;int numUsers = 1;int maxRows = 2;int maxColumns = 50;readRatings(“ratings.txt”, users, ratings, numUsers,maxRows, maxColumns);Return value 2Value of users “ritchie”, “stroustrup”Value of ratings0, 1, 2, 0, 0, …, 0, 0,0, 4, 5, 0, 0, …, 0, 0,In Cloud9 the file should be called readRatings.cpp and it will be one of 9 files youneed to zip together for the Homework 6 (File Submission) on Moodle. Afterdeveloping in Cloud9, this function will be one of the functions needed at the top ofHW6.cpp.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem7, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 8 (25 points) getRatingWe now have a list of usernames and a list of ratings. Now, we want to search for aparticular user’s rating for a particular book title. Write a function that, given a user’s nameand a book’s title, returns the rating that the user gave for that book.? Your function MUST be named getRating.? Your function should take 7 input arguments in the following order:? string: username? string: title of the book? Array of string: users? Array of string: titles? 2-Dimensional int array: ratings – list of ratings for each user [assume ithas 100 rows and 50 columns]? int: number of users whose names/ratings are currently stored in the stringarray/2D array respectively? int: number of books whose titles/ratings are currently stored in the stringarray/2D array respectively? The username and title search should be case insensitive. “Ben, “ben” and “BEN”are one and the same user.? If both the user name and the book title are found in the arrays, then the functionshould return the user’s rating value for that book title.? The function should return the following values depending on cases:? Return the rating value if both user and title are found? Return -3 if the user or the title are not foundValue of users string users[2] = “User1”, “User2”;Value of titles string titles[3] = “Title1”, “Title2”, “Title3”;Value of ratings int ratings[2][3] = 1,4,2,0,5,3;Example 1: Both the userName and bookTitle exists, and the value of rating is non-zeroFunction call getRating(“User1”, “Title2”, users, titles, ratings,2, 3);Return value 4Example 2: The userName does not exist, it returns – 3Function call getRating(“User4”, “Title1”, users, titles, ratings,2, 3);Return value -3Example 3: The bookTitle does not exist, it returns – 3Function call getRating(“User1”, “Title10”, users, titles,ratings, 2, 3);Return value -3Example 4: The userName and the bookTitle do not existFunction call getRating(“User12”, “Title10”, users, titles,ratings, 2, 3);Return value -3In Cloud9 the file should be called getRating.cpp and it will be one of 9 files you needto zip together for the Homework 6 (File Submission) on Moodle. After developing inCloud9, this function will be one of the functions needed at the top of HW6.cpp.Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem8, in the Answer Box, paste only your function definition, not the entire program.Press the Check button. You can modify your code and re-submit (press Check again)as many times as you need to.Problem 9 (20 points) put it all togetherMenu functionality has been provided for you in the starter code on Moodle in the fileHW6.cpp . Download the file and fill in the missing parts in the code which are indicatedby comments in the main()function.Note: the function definitions for Problems 3, 5, 6, 7 and 8 will go in this file aswell. For Problem 9, you need to submit the the entire program HW6.cpp in theanswer box of the CodeRunner auto-grader on Moodle.The menu will run on a loop, continually offering the user five options until they opt toquit. You need to fill in the code for each of the options. You should make use of thefunctions you wrote above (Problems 3 and 5-8), call them, and process the values theyreturn.? In your driver function, you must declare your arrays with the appropriate size.The size of titles and authors array is 50. The size of users array is 100,and the ratings array is 2 dimensional where maxRows is 100 (max number ofusers) and maxColumns is 50 (max number of books).? In your template function the sizes have been declared. Match themaccordingly¦ const static int ratingArrSize = 100;¦ const static int bookArrSize = 50;? Option 1: Initialize library? Prompt the user for a file name.? Pass the file name to your readBooks function.? Print the total number of books in the database in the following format:¦ Total books in the database:? If the function returned -1, then print the following message:¦ No books saved to the database.? If the function returned -2, print¦ Database is already full. No books were added.? When numberOfBooks is equal to size of the array print the followingmessage:¦ Database is full. Some books may have not beenadded.? Option 2: Initialize user catalog? Prompt the user for a file name.? Pass the file name to your readRatings function? Print the total number of users in the database in the following format:¦ Total users in the database:? If the function returned -1, then print the following message:¦ No users saved to the database.? If the function returned -2, print¦ Database is already full. No users were added.? When numUsers is equal to size of the array print the following message:¦ Database is full. Some users may have not beenadded.? Option 3: Display library? Call your printAllBooks function.? Option 4: Get a rating? Prompt the user for a username.? Prompt the user for a title? Pass the username and the title to your getRating function? If the user exists in the system, print the result in the following format:¦ rated with? If the function returns 0, print the result in the following format:¦ has not rated? If the function returns -3, print the result in the following format:¦ or does not exist? Option 5: Quit? Print “good bye!” before exitingBelow is an example of running the HW6 program:Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit1Enter a book file name:badFile.txtNo books saved to the database.Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit1Enter a book file name:books.txtDatabase is full. Some books may have not been added.Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit1Enter a book file name:books2.txtDatabase is already full. No books were added.Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit2Enter a user file name:ratings.txtTotal users in the database: 86Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit3Here is a list of booksThe Hitchhiker’s Guide To The Galaxy by Douglas AdamsWatership Down by Richard Adams………Maus: A Survivor’s Tale by Art SpiegelmanThe Joy Luck Club by Amy TanThe Lord of the Rings by J R R TolkienSelect a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit4Enter username:PunithEnter book title:XKCD 1739Punith or XKCD 1739 does not existSelect a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit4Enter username:amyEnter book title:The Lord of the Ringsamy rated The Lord of the Rings with 2Select a numerical option:======Main Menu=====
Read book file
Read user file
Print book list
Get rating
Quit5good bye!Don’t forget to head over to Moodle to the link Homework 6 CodeRunner. For Problem9, in the Answer Box, you need to submit the the entire program HW6.cpp. Pressthe Check button. You can modify your code and re-submit (press Check again) asmany times as you need to.
Homework 6 checklistHere is a checklist for submitting the assignment:
Complete the code Homework 6 CodeRunner
Submit one zip file to Homework 6 (File Submission). The zip file should benamed, __homework6.zip. It should have following 9 files:? arrayPilgrimage.cpp? floodMap.cpp? Split.cpp? getLinesFromFile.cpp? readBooks.cpp? printAllBooks.cpp? readRatings.cpp? getRating.cpp? HW6.cpp
Homework 6 point summaryCriteria PtsCodeRunner (problem 1 – 9) 150Style and Comments 5Algorithms 5Test cases 20Recitation attendance (Feb 26 or Feb 28)* -30Using global variables -5Total 1805% early submission bonus +5%
if your attendance is not recorded, you will lose points. Make s

READ ALSO  Answer the following six questions for Washington State: - NO PLAGIARISM

QUALITY: 100% ORIGINAL – NO PLAGIARISM.

  • **REMEMBER TO PRECISE PAGE NUMBER**
  • Hit The Order Button To Order A **Custom Paper**

>> 100% ORIGINAL PAPERS FROM AustralianExpertWriters.com <<