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

How to write this code (without using linked lists) in C++ and only C++? This pr

ID: 3822265 • Letter: H

Question

How to write this code (without using linked lists) in C++ and only C++?

This project is based on the Video Store.

The Video Store will do the following tasks:

Rent a video; that is, check out a video.

Return, or check in, a video.

Create a list of videos owned by the store.

Show the details of a particular video.

Print a list of all the videos in the store.

Check whether a particular video is in the store.

Maintain a customer database.

Print a list of all the videos rented by each customer.

The video store has two major components: videos and customers.

The common things associated with a video are as follows:

Title of the movie

Names of the stars

Name of the producer

Name of the director

Name of the production company

Number of copies in the store

The class videoType will be used to implement a video.

The customer object stores information about a customer, such as the first name, last name, account number, and a list of videos rented by the customer.

The class customerType will be used to implement a customer.

The basic operations on an object of type customerType are as follows:

Print the name, the account number, and the list of rented videos.

Set the name and the account number.

Rent a video; that is, add the rented video to the list.

Return a video; that is, delete the rented video from the list.

Show the account number.

The video store will maintain various lists:

A list of all the videos in the store.

A list of all the store’s customers.

Lists of the videos currently rented by each customer

Use the function createVideoList to read the videos data from the videos input file and create a list of videos.

Use another function, createCustomerList, to read the customers data from customers input file and create a list of customers.

Use the function displayMenu to inform the user what to do.

Explanation / Answer

/*
* VideoDB.h
*
* Created on: 22-Apr-2017
*      Author: Rj
*/

#ifndef VIDEODB_H_
#define VIDEODB_H_

#include <iostream>
#include <string>
#include <vector>

using namespace std;

enum status{ rented, inHouse };

struct Video
{
   int _id;
   string _name;
   string _desc;
   status _status;
};

class VideoDB {

private:
   // All videos will be stored in this.
   vector<Video> _videos;
   static int _id;

public:
   VideoDB();
   ~VideoDB();
   void AddVideo(string name, string desc);
   void PrintAll();
   void Rent(int id);
   void Show(int id);
   void CheckIn(int id);
};

#endif /* VIDEODB_H_ */

/*
* VideoDB.cpp
*
* Created on: 22-Apr-2017
*      Author: Rj
*/


#include <iostream>
#include <cstdlib>
#include "VideoDB.h"

using namespace std;

// Initiate id's at 1;
int VideoDB::_id = 0;

/**
* Constructor
*/
VideoDB::VideoDB() : _videos{}
{};

/**
* Destructor
*/
VideoDB::~VideoDB()
{};

/**
* Adds a video to the db
*/
void VideoDB::AddVideo(string name, string desc)
{
   Video newVid{};
   newVid._id = ++_id;
   newVid._name = name;
   newVid._desc = desc;
   newVid._status = inHouse;

   // Insert at the start
   _videos.push_back(newVid);
};

/**
* Prints all the videos to the screen.
*/
void VideoDB::PrintAll()
{
   vector<Video>::iterator it{};

   for (it = _videos.begin(); it < _videos.end(); ++it) {
       cout << it->_id << " " << it->_name
           << ((it->_status == 1) ? " Available": " Unavailable")
           << endl;
   }
};

/**
* Rent a video
*/
void VideoDB::Rent(int id)
{
   vector<Video>::iterator it{};

   for (it = _videos.begin(); it < _videos.end(); ++it) {
       if (it->_id == id) {
           assert(it->_status == inHouse);
           it->_status = rented;
           break;
       }
   }
};

/**
* Show Details of a video
*/
void VideoDB::Show(int id)
{
   vector<Video>::iterator it{};

   for (it = _videos.begin(); it < _videos.end(); ++it) {
       if (it->_id == id) {
           cout << "Id: " << it->_id << " "
               << "Name: " << it->_name << " "
               << "Description: " << it->_desc << endl;
           break;
       }
   }
};

/**
* Checkin the Video.
*/
void VideoDB::CheckIn(int id)
{
   vector<Video>::iterator it{};

   for (it = _videos.begin(); it < _videos.end(); ++it) {
       if (it->_id == id) {
           it->_status = inHouse;
           break;
       }
   }
};

//============================================================================
// Name        : main.cpp
// Author      : Ramachandra jr
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================


#include <iostream>
#include "VideoDB.h"

using namespace std;


int main() {
   VideoDB vdb1{};
   vdb1.AddVideo("Some Video", "Some Desc");
   vdb1.AddVideo("Some Video 1", "Some Desc 1");
   vdb1.PrintAll();
   vdb1.Show(2);
   return 0;
}

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