Comparing marbles using Enums and Class

This is what i have so far, i need to compare two marbles in the main of another cpp file called marble_main that the user inputs. This is where im having difficulties, im lost on this part and my knowledge of classes are some what limited here are the instructions given to me.

Test the class Marble in the file marble_main.cpp.

Create 4 objects of type Marble using 4 constructors. If m1 is a marble with color red and size medium, it should display (red, medium) or (r, m) on the screen.
Compare two objects of type Marble. Let user input 2 pairs of color and size and make 2 marble objects using those input colors and sizes. Print out comparison results, e.g., when user enter r and l for the first marble, then he/she enter r and m for the second marble, the printed result should be "not equal". Note, you should use a while loop for this part in order to let the user continue with the comprisons unless he/she wants to stop it.
Use cin>> and cout<< operators to provide data for testing.


Dont need the Direct answer just some shell code would be nice, i need to see what the next steps will look like.









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef MARBLE_H_ 

#define MARBLE_H_

#include <iostream> 

using namespace std;

class Marble { 

public: 

   class Bad_input {}; // exception class

   enum Color {red, blue, yellow, green}; 

   enum Size {small, medium, large}; 

private: 

   Color color; 

   Size size; 

   // internal functions 

   int random_color(); 

   int random_size(); 

public: 

   // constructors 

   // write 4 constructors here: 

    Marble(); //-- random color and size 

    Marble(Color c); //-- given color, random size 

   Marble(Size s); //-- random color, given size 

   Marble(Color c, Size s); //-- given color and size 

   Color get_color() const;   

   Size get_size() const; 

   void set_color(Color c);

   void set_size(Size s);
};

// helper functions

bool operator==(const Marble& m1, const Marble& m2);      

ostream& operator<<(ostream& os, const Marble& m); 

istream& operator>>(istream& is, Marble& m);

#endif // end of the file marble.h  


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include "marble.h"
  
  
  int Marble::random_color(){
    return rand()% 4+1;
  }
  
  int Marble::random_size(){
  return rand()% 3+1;
  }
  
  Marble::Marble(){
    color=(Color)random_color();
    size=(Size)random_size();
  }
  
  Marble::Marble(Color c){
  color=c;
  size=(Size)random_size();
  }
  
  Marble::Marble(Size s){
  size=s;
  color=(Color)random_color();
  }
   
  Marble::Marble(Color c, Size s){
  size=s;
  color=c;
  }
  
 Marble::Color Marble::get_color() const{
  return color;
  }  

 Marble::Size Marble::get_size() const{
  return size;
  } 

  void Marble::set_color(Color c){
  color=c; 
  }

  void Marble::set_size(Size s) {
  size=s;
  }
  
  bool operator==(const Marble& m1, const Marble& m2){
  
  }
Last edited on
Topic archived. No new replies allowed.