Class with setter and displayer : Class Access « Class « C++






Class with setter and displayer

  
#include <iostream>
#include <string.h>
using namespace std;
class movie 
{
public:
  char name[64];
  char first_star[64];
  char second_star[64]; 
  void show_movie(void)
    {
      cout << "Movie name: " << name << endl;
      cout << "Starring: " << first_star << " and " << second_star << endl << endl;
    }
  
  void initialize(char *movie_name, char *first, char *second)
    {
      strcpy(name, movie_name);
      strcpy(first_star, first);
      strcpy(second_star, second);
    }
};

int main(void)
{
   movie fugitive, sleepless;

   fugitive.initialize("A", "B", "C");
   sleepless.initialize("D", "E", "F");

   cout << fugitive.name << " and " << sleepless.name << endl;

   cout << fugitive.first_star << endl;
}
  
    
  








Related examples in the same category

1.You may change access specifications as often as you like within a class declaration