Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

Your task in this homework is to write a program that helps your future self to choose the best date to schedule your vacation visit for maximum fun.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Individual Homework: Vacation Planning

 

Objectives

  1. Practice reading data from files and using istream states (e.g. eof(), bad(), clear())

  2. Practice computing results through the manipulation of information in different

  3. Practice traversing arrays within array

 

Overview

Your cousins plan to write a book titled "Strength Training for Video-game Players" in 2023. Due to the success of their previous books “Fitness for Busy Engineers” and “Cooking Basics for Engineers”, many publishers fought to acquire the rights for the upcoming book. The winning bid provided your cousins with a place to live while writing the book: a house in Hawaii available from January 1st to December 31st 2023.

 

As part of the research for their book, your cousins will play one video-game each day for six hours. They shared with you their plan through a file listing for each day of the year the video-game chosen for the day.

 

You hope to have your diploma by summer 2022 and have a job that will allow you to go on vacation in Hawaii anytime in 2023. You want to choose a period for your vacation such that you get to play your favorite games with your cousins. You state your video-game preferences by assigning a rating from 0 to 5 to each of the games that your cousins plan to play.

 

Your task in this homework is to write a program that helps your future self to choose the best date to schedule your vacation visit for maximum fun. For that purpose, you need to implement the following four functions: readPrefs, readPlan, computeFunLevel, and findBestVacation. You also need to implement the main program as described below.

 

The program

Your program reads the following information from the user:

  • Number of games ngames (0 < ngames <= 200)

  • Duration of the vacation duration (0 < duration <= 365)

  • Name of three input files:

    • File with game titles, e.g., game-titles.txt

    • File with game preferences, e.g., txt

    • File with year plan, e.g., txt

 

As an output, your program prints the start day for the best vacation option.

Your program also prints the titles of the games that will be played in this vacation option.

 

You need to implement the four functions described in this document. Your code must use these four functions and the two functions we provide in starter code (files provided.h and provided.cpp)

 

The functions you need to write

 

/*  Function readPrefs

  • fileName: c-style String, i.e., array of chars ended by ‘�’

  • ngames: number of games

  • prefs: array of integers created with MAX_NB_GAMES=200

  •  
  • Return value: described below

*/

int readPrefs(char fileName[], int ngames, int prefs[]);

 

The function reads your game preferences from file fileName and stores the information in the array prefs, returning the number of valid lines present in the file. For any game without a rating provided in the file, you should store 0 as the rating in its entry in array prefs. If there is a problem with opening the file fileName, the function returns -1.

 

Every line in the file contains two items. A valid line contains two integers: a game id (an integer between 0 and ngames - 1) and your rating for the game (an integer between 0 and 5). Any invalid line in the file should be ignored. You can assume that lines in the file are unique, i.e., if one line contains the rating for one game, no other line will provide a rating for the same game.

For example, if the file prefs.txt contains 5 lines (Figure 1.a), then readPrefs(“prefs.txt”, 100, prefs) will return 3 and the array prefs will store information as pictured in Figure 1.b. In this example, the second and fourth lines in the file are ignored as they contain invalid data.

/*  Function readPlan

  • fileName: c-style String, i.e., array of chars ended by ‘�’

  • plan: array of integers created with 365 positions

  • games: it is not used. It is here as a leftover from a version

  • that asked for input invalidation. Simply ignore

  • Return value: as described below

*/

int readPlan(char fileName[], int ngames, int plan[]);

 

The function reads your cousins’ plans from file fileName and stores the information in the array plan. You may assume that the information in the file is in chronological order, every line contains valid information, and no day is missing. Each line of the file contains the day (an integer between 1 and 365) and the id for the game planned for the day. The figures below show as an example the first 10 (figure 2.a) and the last 10 (figure 2.b) lines is a file. As a result of executing the function readPlan(“plan.txt”, plan) the array plan will hold value

If there is a problem with opening the file fileName, the function returns -1; otherwise, it returns 0.

Notice that we chose to store the plan for day k in plan[k]. With this choice, we leave position

0 (plan[0]) uninitialized and unused in the program.

 

/*  Function computeFunLevel

  • start: first day of the vacation (1 <= start < 365)

  • duration: number of vacation days (duration >= 1)

  • prefs: prefs[k] indicates the rating specified for game k

  • ngames: number of elements in the array prefs

  • plan: array with 366 positions with the sequence of games

  • to be played over the year. In other words,

  • plan[k] indicates the game planned for day k (1 <= k <= 365)

  • Return value: Explained

*/

int computeFunLevel (int start, int duration, int prefs[],

int ngames, int plan[]);

 

The function returns the sum of the ratings for games played during the vacation period. If the duration is longer than the number of days left in the year, the function returns -1.


For example, for ngames = 5, assuming the arrays hold the data as in the picture below:

 

  • computeFunLevel(1, 1, prefs, 5, plan) returns 0, because the game planned for day 1 is game 2 and the rate in prefs for game 2 is

  • computeFunLevel(1, 4, prefs, 5, plan) returns 0 + 1 + 5 + 5 = 11

  • computeFunLevel(7, 2, prefs, 5, plan) returns 2 + 0 = 2

  • computeFunLevel(361, 5, prefs, 5, plan) returns 1 + 2 + 0 + 5 + 2 = 10

  • computeFunLevel(364, 3, prefs, 5, plan) returns -1, as it is not possible to have a 3-day vacation starting on day 364 within the

 

/*  Function findBestVacation

  • duration: number of vacation days

  • prefs: prefs[k] indicates the rate specified for game k

  • ngames: number of elements in the array prefs

  • plan: array with 366 positions with the sequence of games

  • to be played over the year. In other words,

  • plan[k] indicates the game planned for day k (1 <= k <= 365)

  • Return value: Explained

*/

int findBestVacation (int duration, int prefs[], int ngames,

int plan[]);

 

This function receives the duration of vacation and returns the earliest start date that results in the highest “fun level” available. For example, for the prefs and plan below and duration

== 4, findBestVacation will return 4.

 
   

 

 

 

The functions you do not need to write

We provide the code for the following functions (files provided.h and provided.cpp). They are ready for you to use in your main program.

 

/*  Function readGameTitles

  • fileName: c-style String, i.e., array of chars ended by ‘�

  • ngames: number of games cousins are bringing to the house

  • gameTitles: 2d-array where row i stores the title for game i

  • Return value: Explained

 

*/

int readGameTitles (char fileName[], int ngames,

char  gameTitles[MAX_NB_GAMES][MAX_TITLE_SIZE])

 

The function will read from a file the titles for the games, storing the information in array gameTitles such as gameTitles[k] contains the title of the game with id = k. The title is stored as an array of chars ended by ‘�’, i.e., a C-style string.

If the file does not contain information on title x, gameTitles[x] will be “Unknown Title”.

 

If there is a problem with opening the file fileName, the function returns -1; otherwise, it returns 0.

 

/*  Function printGamesPlayedInVacation

  • start: first day of the vacation (1 <= start < 365)

  • duration: number of vacation days

  • plan: array with 366 positions with the sequence of games

  • to be played over the year. In other words,

  • plan[k] indicates the game planned for day k (1 <= k <= 365)

  • gameTitles: array with game titles

  • ngames: number of games

  • Return value:

*/

void printGamesPlayedInVacation(int start, int duration, int plan[], char gameTitles[MAX_NB_GAMES][MAX_TITLE_SIZE],

int ngames);

 

The function prints on the standard output the game titles played during a vacation period, without repeating titles played in multiple days.

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
986 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
795 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
502 Answers Hire Me