Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello I need help finding the solution to this problem that needs to be solved i

ID: 3842263 • Letter: H

Question

Hello I need help finding the solution to this problem that needs to be solved in C. THANK YOU!

The yellowbox sample code is the following:

Project Description Redbox is a nationwide network of kiosks where customers can rent DVDs, Blu-Ray discs, and video games. For this project, we will implement a program named "YellowBox that emulates a Redbox kiosk (to a very limited degree) using arrays, structures, and file l/O. We have given you a skeleton source code file named "yellowbox.c"; you may use this as a starting point for your project (for example, a fully-working main() function is already provided for you), or re- implement everything on your own Follow the steps below to complete the project assignment. Two sample data files have been provided on Blackboard for you to use while testing your code 1. Start by defining some useful data types and global variables 1. Define a struct to represent a particular movie. A movie struct contains a string that holds the movie's title, and an integer that tracks the number of copies that are currently in stock. For example, a variable of this type might record that the kiosk currently contains 3 copies of "Braveheart" 2. Create a array to hold your movie structures. You may assume that our kiosk will track no more than 50 distinct movie titles 3. Create a global integer variable to track the total number of distinct movie titles that the kiosk knows about (i.e., has seen at some point through a transaction request). This variable's value also indicates the total number of occupied positions in your movie array. Initialize this variable to 0 4. Create a global integer variable to track the total number of discs that are currently held in the kiosk. Initialize this variable to 0 2. Complete the findMovie helper function, which locates a particular movie title in your array int findMovie (char *title) If the kiosk is currently empty, this function returns -1 Otherwise, use a loop to examine each movie structure in your array of movies. If the current movie's title matches the title you are searching for (use the strcmp function compare two strings), return the index of the matching movie structure from your array. you complete the loop without finding a match, return -1 to indicate that the title is not present

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_MOVIE_TITLES    50 /// max number of distinct movies in the kiosk

#define MAX_DISCS   50 /// max number of discs that the kiosk can hold in total

#define MAX_MOVIE_NAME_CHARS    50 /// max number of characters that a movie title may contain, excluding ''

/// data structures
struct movies
{
    char name[MAX_MOVIE_NAME_CHARS];
    //
    unsigned int copies; /// number of copies in stock
    //

}typedef movies;

/// create an array of 50 movies
movies titles[MAX_MOVIE_TITLES];

//
unsigned int totalMovies = 0; /// holds total number of distinct movie titles present in the kiosk
//
unsigned int totalDiscs = 0; /// total number of discs currently in the kiosk
//
unsigned int kioskFillIndex = -1; /// holds the index of the last element filled in the array of movies, to add a title, increment this and use as the index of the structure array
//

/// Function searches for a movie in the array of movies and returns its index if present, or returns -1
int findMovie(char *title)
{
    //
    int i;
    //
    /// return -1 if kiosk empty
    if (totalDiscs == 0)
        return -1;
    //
    else{
        //
        for(i = 0; i < MAX_MOVIE_TITLES; i++)
        {

            /// return the index of the movie if found
            if (strcmp(titles[i].name, title) == 0)
                return i;
            //
        }
        /// return -1 if the movie was not found
        return -1;
    }
}

//
/// prints the inventory status
void printInventory()
{

    //
    int i;
    //
    if (totalDiscs == 0)
        printf("========= Kiosk is empty ============ ");
    //
    else{
        //
        printf("Movie Title                 Copies ");
        //
        printf("-----------                 ---------");
        //
        for(i = 0; i < MAX_MOVIE_TITLES; i++)
        {
            //
            if (titles[i].copies > 0)
            {
                /// only print status of those movies which have at least one copy
                printf("%s                      %d ",titles[i].name, titles[i].copies);
            }

        }
    }
}

//

/// add a movie title to the kiosk
int addMovie(char *title)
{
    //
    int titleIndex = -1;
    //
    /// return 0 if kiosk is at max disc capacity
    if (totalDiscs == MAX_DISCS)
        return 0;
    //
    else
    {
        //
        titleIndex = findMovie(title); /// check if the movie exists
        //
        /// add to kiosk if movie not already present
        if (titleIndex == -1)
        {
            //
            kioskFillIndex ++; /// increment the structure fill index to locate an empty cell
            //
            titles[kioskFillIndex].copies++; /// add a copy of the title
            //
            strcpy(titles[kioskFillIndex].name, title);
            //
            totalDiscs++; /// increment the total number
            //
            totalMovies++; /// increment the total number of movie titles seen
            //
            return 1;
        }
        //
        /// if movie present, just increment the number of discs
        else{
            //
            titles[titleIndex].copies++; /// increment copies of the title
            //
            totalDiscs++; /// increment total number of discs
        }
    }
    //
    return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote