Starting Computing Homework 6

$24.99 $18.99

ooks.txt​) Here is a list of books The Hitchhiker’s Guide To The Galaxy by Douglas Adams Watership Down by Richard Adams The Five People You Meet in Heaven by Mitch Albom Speak by Laurie Halse Anderson …   In Cloud9 the file should be called ​printAllBooks.cpp and it will be one of 9 files you…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:

Description

5/5 – (2 votes)

ooks.txt​)

Here is a list of books

The Hitchhiker’s Guide To The Galaxy by Douglas Adams Watership Down by Richard Adams

The Five People You Meet in Heaven by Mitch Albom Speak by Laurie Halse Anderson …

 

In Cloud9 the file should be called ​printAllBooks.cpp and it will be one of 9 files you need to zip together for the ​Homework 6 (File Submission) ​on Moodle. After developing in Cloud9, 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 Problem 6, 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) readRatings

Write 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 is followed 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 of the format:

 

ratings.txt

ritchie,3,3,3

stroustrup,0,4,5

gosling,2,2,3

rossum,5,5,5

 

Rating
Meaning

0
Did not read

1
Hell no – hate it!!

2
Don’t like it.

3
Meh – neither hot nor cold

4
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.The number of rows corresponds to the number of users, and the number of columns 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 username in 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 (“,”) as the delimiter. When you copy your code in the answer box on Moodle Coderunner, 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 text file) 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 the ratings​2D array, return -2

◦ When ​numUsers is smaller than the maximum number of rows in the ratings 2D array, keep the existing elements in ​users array and ratings array, then read data from file and add (append) the data to the arrays. The number of users stored in the arrays cannot exceed the size of 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,4

Myth,2,2,4,5,1

Sphyer,3,1,0,0,5

Daequan,0,0,0,0,2
Function 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
4
Value of ​users
{“Ninja”, “Myth”, “Sphyer”, “Daequan”, “”, “”,

“”, “”, “”, “”}
Value of ​ratings
{

{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},

{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 and a bad file is given

Function 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
-1

Value of ​users
{“”, “”, “”, “”, “”, “”, “”, “”, “”, “”}
Value of ​ratings
{
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 3:​The ​users​and ​ratings​arrays are full, so ​readRatings​returns -2.

moreRatings.txt
alpha,0,1,2,3,4

beta,0,1,2,3,4

gamma,0,1,2,3,4

delta,0,1,2,3,4
Function 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
-2

Value of ​users
{“Ninja”, “Myth”,
“Sphyer”, “Daequan”}
Value of ​ratings
{
…, 0, 0},

{0, 1, 2, 3, 4,

{2, 2, 4, 5, 6,
…, 0, 0},

{3, 1, 0, 0, 5,
…, 0, 0},

{0, 0, 0, 0, 2,
…, 0, 0}

}

Example 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 the function returns the ​size​of the array.

ratings.txt
stroustrup,0,4,5

gosling,2,2,3

rossum,5,5,5
Function call
string users[2] = {“ritchie”};

int ratings[2][50] = {{0, 1, 2, 0, 0, …, 0, 0}

{0, 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
2
Value of ​users
{“ritchie”, “stroustrup”}
Value of ​ratings
{

{0, 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 you need to zip together for the ​Homework 6 (File Submission) ​on Moodle. After
developing in Cloud9, 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 Problem 7, 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) getRating

We now have a list of usernames and a list of ratings. Now, we want to search for a particular user’s rating for a particular book title. Write a function that, given a user’s name and 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 it has 100 rows and 50 columns]

◦ int​: number of users whose names/ratings are currently stored in the string array/2D array respectively

◦ int​: number of books whose titles/ratings are currently stored in the string array/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 function should 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 found

 

Value 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-zero

 

Function call
getRating(“User1”, “Title2”, users, titles, ratings,

2,
3);

Return value
4

 

 

Example 2:​The ​userName​does not exist, it returns – 3

Function call
getRating(“User4”, “Title1”, users, titles, ratings,

 

2,
3);

Return value
-3

 

 

 

 

Example 3:​The ​bookTitle​does not exist, it returns – 3

Function call
getRating(“User1”,
“Title10”,
users,
titles,

 

ratings, 2, 3);

 

 

Return value
-3

 

 

 

 

Example 4:​The ​userName​and the ​bookTitle​do not exist

 

Function call
getRating(“User12”,
“Title10”,
users,
titles,

 

ratings, 2, 3);

 

 

Return value
-3

 

 

 

 

 

 

In Cloud9 the file should be called ​getRating.cpp and it will be one of 9 files you need to zip together for the ​Homework 6 (File Submission) ​on Moodle. After developing in Cloud9, 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 Problem 8, 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 together

Menu functionality has been provided for you in the starter code on Moodle in the file HW6.cpp​. Download the file and fill in the missing parts in the code which are indicated by comments in the ​main()​function.

Note: the function definitions for Problems 3, 5, 6, 7 and 8 will go in this file as well. For Problem 9, you need to submit the the entire program HW6.cpp in the answer box of the CodeRunner auto-grader on Moodle.

The menu will run on a loop, continually offering the user five options until they opt to quit. You need to fill in the code for each of the options. You should make use of the functions you wrote above (Problems 3 and 5-8), call them, and process the values they return.

 

• 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 of users) and ​maxColumns ​is 50 (max number of books).

◦ In your template function the sizes have been declared. Match them accordingly

▪ 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: <numberOfBooks>

◦ 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 following message:

▪ Database is full. Some books may have not been added.
• 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: <numUsers>

◦ 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 been added.

• 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:

▪ <name> rated <title> with <rating>

◦ If the function returns 0, print the result in the following format:

▪ <name> has not rated <title>

◦ If the function returns -3, print the result in the following format:
▪ <name> or <title> does not exist

• Option 5: ​Quit
◦ Print ​“good bye!”​before exiting
Below is an example of running the ​HW6​program:

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

1

Enter a book file name:

badFile.txt

No books saved to the database.

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

1

Enter a book file name:

books.txt

Database is full. Some books may have not been added.

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

1

Enter a book file name: books2.txt
Database is already full. No books were added.

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

2

Enter a user file name:

ratings.txt

Total users in the database: 86

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

3

Here is a list of books

The Hitchhiker’s Guide To The Galaxy by Douglas Adams Watership Down by Richard Adams …

Maus: A Survivor’s Tale by Art Spiegelman The Joy Luck Club by Amy Tan

The Lord of the Rings by J R R Tolkien

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

4

Enter username:

Punith

Enter book title:

XKCD 1739

Punith or XKCD 1739 does not exist

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

4

Enter username:

amy

Enter book title:

The Lord of the Rings

amy rated The Lord of the Rings with 2

Select a numerical option:

======Main Menu=====

1. Read book file

2. Read user file

3. Print book list

4. Get rating

5. Quit

5

good bye!

Don’t forget to head over to Moodle to the link ​Homework 6 CodeRunner​. For Problem 9, in the Answer Box, ​you need to submit the the entire program HW6.cpp​. Press the Check button. You can modify your code and re-submit (press Check again) as many times as you need to.

 

6. Homework 6 checklist

Here is a checklist for submitting the assignment:
1. Complete the code ​Homework 6 CodeRunner
2. Submit one zip file to ​Homework 6 (File Submission)​. The zip file should be named, ​<firstName>_<lastName>_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

 

 

 

7. Homework 6 point summary

 

Criteria

Pts

CodeRunner (problem 1 – 9)

Style and Comments

Algorithms

Test cases

Recitation attendance (Feb 26 or Feb 28)* Using global variables Total

5% early submission bonus

150

5

5

20

-30

-5

180

+5%

• if your attendance is not recorded, you will lose points. Make sure your attendance is recorded on Moodle.

Starting Computing Homework 6
$24.99 $18.99