Programming Fundamentals: Assignment No 4
Programming Fundamentals: Assignment No 4
Assignment no 4
Q1. Examine the “card game example” from your book chapter 4, compile it using visual studio and
attach screenshots of code with output with this assignment. Write down your comments about this
program at the end?
Solution:
// cardobj.cpp
// cards as objects
#include <iostream>
////////////////////////////////////////////////////////////////
class card
private:
public:
{}
{}
};
//--------------------------------------------------------------
else
switch (number)
switch (suit)
//--------------------------------------------------------------
}
////////////////////////////////////////////////////////////////
int main()
int position;
switch (position)
else
return 0;
return true;
else
return false;
In isEqual() the argument is called c2 as a reminder that there are two cards in the comparison:
The first card is the object of which isEqual() is a member. The expression if( chosen.isEqual(prize) )
in main() compares the card chosen with the card prize.
Here’s the output when the user guesses an incorrect card: Card 1 is the 7 of clubs
Answer:
By default, spring is 0, summer is 1 and so on. You can change the default value of an enum element
during declaration (if necessary).
enum season
{ spring = 0,
summer = 4,
autumn = 8,
winter = 12
};