El proyecto trata sobre un programa para los fanáticos a las películas, este proyecto esta dividido en 5 partes:
main.cpp
,Movies.cpp
,Movies.h
,Movie.cpp
,Movie.h
.
De los cuales dos de ellas (los archivos con la extensión .h
) son clases.
Al terminar mi proyecto, intento compilarlo, pero me aparece un error de compilación, he revisado y simplemente no encuentro el problema, si alguien me puede ayudar seria grandioso.
A continuación, dejo los códigos respectivos (en sus encabezados dejo el correspondiente a cada uno):
Movie.h:
#pragma once
#ifndef _MOVIE_H_
#define _MOVIE_H_
#include string>
class Movie
{
private:
std::string Name;
std::string Rating;
int Watched;
public:
Movie(std::string name, std::string Rating, int Watched);
Movie(std::string name, std::string Rating, int Watched);
~Movie();
void set_name(std::string Name) { this->Name = Name; }
std::string get_name() const { return Name; }
void set_Rating(std::string Rating) { this->Rating = Rating; }
std::string get_Rating() const { return Rating; }
void set_Watched(int Watched) { this->Watched = Watched; }
int get_Watched() const {return Watched; }
void increment_Watched() {++Watched;}
void display() const;
};
#endif
Movie.cpp:
#include "Movie.h"
#include <iostream>
Movie::Movie(std::string Name, std::string Rating, int Watched)
:Name(Name), Rating(Rating), Watched(Watched) {
}
Movie::Movie(const Movie & source)
: Movie {source.Name,source.Rating,source.Watched } {
}
Movie::~Movie(){
}
void Movie::display()const {
std::cout << Name << ", " << Rating << ", " << Watched << std::endl;
}
Movies.h:
#pragma once
#ifndef _MOVIES_H_
#define _MOVIES_H_
#include <vector>
#include <string>
#include "Movie.h"
class Movies
{
private:
std::vector<Movie> movies;
public:
Movies();
~Movies();
bool add_Movie(std::string Name, std::string Rating, int Watched);
bool increment_Watched(std::string Name);
void display()const;
};
#endif
Movie.cpp:
#include "Movies.h"
#include <iostream>
Movies::Movies(){
}
Movies::~Movies() {
}
bool Movies::add_Movie(std::string Name, std::string Rating,int watched) {
return false;
}
bool Movies::increment_Watched(std::string Name) {
return false;
}
void Movies::display() const{
}
main.cpp:
#include <iostream>
#include "Movies.h"
void increment_watched(Movies &movies, std::string name);
void add_movie(Movies &movies, std::string name, std::string rating, int watched);
void increment_watched(Movies &movies, std::string name) {
if (movies.increment_watched(name)) {
std::cout << name << " watch incremented" << std::endl;
} else {
std::cout << name << " not found" << std::endl;
}
}
void add_movie(Movies &movies, std::string name, std::string rating, int watched) {
if (movies.add_movie(name,rating,watched)) {
std::cout << name << " added" << std::endl;
} else {
std::cout << name << " already exists" << std::endl;
}
}
int main() {
Movies my_movies;
my_movies.display();
add_movie(my_movies, "Big", "PG-13",2);
add_movie(my_movies,"Star Wars", "PG",5);
add_movie(my_movies,"Cinderella", "PG",7);
my_movies.display();
add_movie(my_movies,"Cinderella", "PG",7);
add_movie(my_movies,"Ice Age", "PG",12);
my_movies.display();
increment_watched(my_movies,"Big");
increment_watched(my_movies,"Ice Age");
my_movies.display();
increment_watched(my_movies,"XXX");
return 0;
}
Output
(debajo de la consola) >Show output from: Build
(encima de la consola) donde el compilador emite los errores explicando (más o menos) qué hay mal en tu código.