Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
===========================
Main.Cpp
===========================
#include <iostream>
#include <list>#include <iterator>
#include "Data.h"

int main(){
    moviesLL m;
    return 0;
}

C++
==================================
Data.h
==================================
#pragma once

#include <iostream>
#include <list>#include <iterator>
using namespace std;

class movieList
{
public:
    int movieCode;
    string movieTitle;
    string movieGenre;
    int yearReleased;
    void insertMovie();

    movieList(int movieCode, string movieTitle,string movieGenre, int yearReleased){
        this->movieCode = movieCode;
        this->movieTitle = movieTitle;
        this->movieGenre = movieGenre;
        this->yearReleased = yearReleased;
    }
};
class moviesLL
{
private:
    list<movielist>movies;
public:
    moviesLL(){
    int option = 5;
    do{
        option = menu();

        switch(option)
        {
        case 1:
            insertMovie();
            break;
        case 2:
            deleteMovie();
            break;
        case 3:
            appendMovie();
            break;
        case 4:
            showMovieDetails();
            break;
        case 5:
            printMovieList();
            break;
        case 6:
             movies.clear();
            break;
        default:
            cout << "Invalid Input";
        }
    }while(option != 6);
};

int menu(){
    int option;
    cout << "Menu: " <<endl;
 cout="" <<="" "1.="" insert="" new="" movie"="" <<endl;
="" "2.="" rent="" a="" "3.="" return="" "4.="" show="" movie="" details"="" "5.="" print="" movies="" list"="" "6.="" quit="" the="" program"="" <<endl;

="" "enter="" your="" choice:="" ";
="" cin="">> option;
    return option;
}

void insertMovie()
{
    cout << "Enter new Movie Code: ";
    int movieCode;  cin >> movieCode;

    cout << "Enter new Movie Title: ";
    string movieTitle;
    cin.ignore();
    getline(cin, movieTitle);

    cout << "Enter new Movie Genre: ";
    string movieGenre;
    cin.ignore();
    getline(cin, movieTitle);


    cout << "enter new Movie Releasing Year: ";
    int yearReleased;       cin >> yearReleased;
    movies.push_back(movieList(movieCode, movieTitle, movieGenre, yearReleased));
    return;
}

void deleteMovie()
{
    cout << "Enter the Movie Code of movie you want: ";
    int movieCode;      cin >> movieCode;

    list<movielist> :: iterator it;
    bool movieFound = false;
    for(it = movies.begin(); it != movies.end(); it++) {
            if(it->movieCode == movieCode){
                    movieFound = true;
            movies.erase(it);
            cout << "Movie Rented ";
            break;
    }
}
if(!movieFound){
        cout << "No Movie Found with that Movie Code!!!";
}
return;
}
void appendMovie(){
    cout << "Enter details of Movie You Want to Return: ";

    cout << "Enter your Movie Code: ";
    int movieCode; cin >> movieCode;

    cout << "Enter your Movie Title: ";
    string movieTitle;
    cin.ignore();
    getline(cin,movieTitle);

    cout << "Enter your Movie Genre: ";
    string movieGenre;
    cin.ignore();
    getline(cin,movieGenre);


    cout << "enter your Movie Releasing Year: ";
    int yearReleased;       cin >> yearReleased;

    movies.push_back(movieList(movieCode, movieTitle, movieGenre, yearReleased));
    return;
}

void showMovieDetails()
{
    cout << "Enter the Movie Title you want to look for details: ";
    string movieTitle;
    cin.ignore();
    getline(cin,movieTitle);

    list<movielist> :: iterator it;
    bool movieFound = false;
    for(it = movies.begin(); it != movies.end(); it++){
            if(it->movieTitle == movieTitle){
                movieFound = true;
                cout << "Movie Details: ";
                cout << "Movie Code: " << it->movieCode;
                cout << "Movie Title: " << it->movieTitle;
                cout << "Movie Genre: " << it->movieGenre;
                cout << "Movie Releasing Year: " << it->yearReleased;
                break;
            }
    }
    if(!movieFound)
    {
        cout << "No Movie Found with that Title";
    }
    return;
}

void printMovieList()
{
    list<movielist> :: iterator it;
    bool movieFound = false;
    cout << "Movies Details:";
    for(it = movies.begin(); it != movies.end(); it++) {
        movieFound = true;
        cout << "Movie Code: " << it->movieCode;
        cout << "Movie Title: " << it->movieTitle;
        cout << "Movie Genre: " << it->movieGenre;
        cout << "Movie Releasing Year: " << it->yearReleased;
    }
    if(!movieFound){
        cout << "Sorry were do not have any movies";
    }
    return;
    }
};


What I have tried:

I tried to separating them but I don't know how because I am just a just a beginner.
Posted
Updated 12-Jun-22 21:41pm
v2

Create Data.cpp file. Leave in Data.h declarations only. Move all implementation into the Data.cpp. Include Data.cpp into your build chain
 
Share this answer
 
.H files are headers: they should not contain actual code, just definitions.

Things like constant values, function signatures and so forth: H - C/C++ Header File Format[^]

What they don't contain is code:
C++
void insertMovie()
{
    cout << "Enter new Movie Code: ";
    int movieCode;  cin >> movieCode;

    cout << "Enter new Movie Title: ";
    string movieTitle;
    cin.ignore();
    getline(cin, movieTitle);

    cout << "Enter new Movie Genre: ";
    string movieGenre;
    cin.ignore();
    getline(cin, movieTitle);


    cout << "enter new Movie Releasing Year: ";
    int yearReleased;       cin >> yearReleased;
    movies.push_back(movieList(movieCode, movieTitle, movieGenre, yearReleased));
    return;
}
That all belongs in the .CPP file with a #include to bring in the .H file definitions.

And do yourself a favour: fix your indentation - some of your code is very hard to read!
 
Share this answer
 
As OriginalGriff wrote, a header(.h) should only contain declarations and constants.
Only the declaration of the class would then be found in the header.
It looks something like this:
C++
// == == == == == == == == == == == == == == == == ==
// Data.h
// == == == == == == == == == == == == == == == == ==

...

class movieList
{
public:
	movieList(int movieCode, string movieTitle, string movieGenre, int yearReleased);
	int    GetmovieCode() { return movieCode; }
	string GetmovieTitle() { return movieTitle; }
	string GetmovieGenre() { return movieGenre; }
	int    GetyearReleased() { return yearReleased; }
private:
	int movieCode;
	string movieTitle;
	string movieGenre;
	int yearReleased;
};

class moviesLL
{
public:
	moviesLL() {};
	int menu();
	void insertMovie();
	void deleteMovie();
	void appendMovie();
	void appendMovie(int movieCode, string movieTitle, string movieGenre, int yearReleased);
	void showMovieDetails();
	void printMovieList();
	void deleteMovieList();
private:
	list<movieList> movies;
};

The implementation, i.e. the associated code, then belongs in the Data.cpp file.
C++
// == == == == == == == == == == == == == == == == ==
// Data.cpp
// == == == == == == == == == == == == == == == == ==

#include "data.h"

movieList::movieList(int movieCode, string movieTitle, string movieGenre, int yearReleased)
{
	this->movieCode = movieCode;
	this->movieTitle = movieTitle;
	this->movieGenre = movieGenre;
	this->yearReleased = yearReleased;
};

void moviesLL::deleteMovieList()
{
	movies.clear();
}

...

A test program could then look like this:
C++
// == == == == == == == == == == == == == =
// Main.Cpp
// == == == == == == == == == == == == == =

#include "data.h"

int main() {
  moviesLL m;

  m.appendMovie(1234, "Just do it", "Science", 2022);
  m.printMovieList();

  return 0;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900