Class with only public fields and methods : Public « Class « C++






Class with only public fields and methods

   
#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);
     void initialize(char *name, char *first, char *second);
};

void movie::show_movie(void)
{
   cout << "Movie name: " << name << endl;
   cout << "Starring: " << first_star << " and " << second_star << endl << endl;
}

void movie::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", "F", "B");
   sleepless.initialize("C", "D", "E");
   cout << fugitive.name << " and " << sleepless.name << endl;
   cout << fugitive.first_star << endl;
}
  
    
    
  








Related examples in the same category

1.Illustrates the use of a public variableIllustrates the use of a public variable
2.Assign the public object member address to a pointerAssign the public object member address to a pointer
3.public class extending
4.field in struct is public by default
5.Virtual public inheritance
6.public data field
7.public inheritance from three parent classes