Error in declaration of class Card
Card(suit = clubs, int = 1);should be
Card(suit ss = clubs, int = 1);
for(suit s=clubs; s<spades; ...)I think we need
for(suit s=clubs; s<=spades; ...)so that the pack actually contins the suit of spades, as well as clubs, diamonds, and hearts.
void Cardstack::shuffle()
{
srand(time(0));
for (int i = 0; i<stack.size()-1; i++)
{ // pick the i'th card from rest of stack
int n1 =i+ rand() % (stack.size()-i);
Card temp = stack[i];
stack[i] = stack[n1];
stack[n1]= temp;
}
}I may have the details wrong above...
All C++ compilers handle #include "foo.bar" in the same way. The
open the foo.bar file and read it -- as if you had included a copy
in you code.
What are constructors
They are member functions of a class that have the same name and
initialize the data memebers of the class. For more info follow
the links constructed by
[ lookup.php?search=constructor ]
Are there any other ways to initialize data memebers other than using constructors
Not reliably.
What you often find is a setter memebr function that changes the value of a data memebr. For example if you have
int knobs;in a class, then you may also have
void setKnobs(int newvalue){ knobs = newvalue; }
A good rule is to only add a setter function when it is going to be used by another class.
What are some other type of prgrams in which object oriented programming can be used
OO has been used ofr all applications, and all sizes of prgram from the
smallest "Hello World" to whole operating systems, like Linux.
The only case for not using objects is when the program is trivial in a non-OO language. Fir example I do a lot of programming using the Linux shell and tools. They are not OO but are very powerful for sorting, editting, searching, summarizing tables.
Similarly your grades a kept in a spreadsheet these days. It is more flexible and easiy to use than the Object Based Hypercard system Used in the late 1980s and early 90s.
Dont you need a main program to use a class
Yes. With out a main function the program never starts running.
Becasue 'main' is where it starts.
However -- a class may be used by another class, and that class can be use by main.
Why is the simplest solution usually the right one
Simple solution don't have as many problems and are easier to
fix when things change.
This philosophy is also a guide for us to avoid unneeded complexity.
When drawing is there an easy way to combine several classes into one
What a cool idea!
Not as far as I know. None of the tools I've used in the last 20 years had this feature. You just have copy in the attributes and operations and connections...
It is best to only have one class in your diagram from each name. We ended up with several "Person" classes in lab08 because the book illustrated each concept in a different diagram.
If you wanted a user to input a function with variable what type could you use
C++ is a compiler it handles and stores functions before the program runs.
After then there is no compiler running to accept and insert new code.
More -- this is a very dangerous feature. Whenever a language has allowed users to supply code somebody has exploited to take control ofthe computer on which the program runs.
A quick example -- the first internet worm caused utter havoc by using email to send and compile code accross the internet. It sent a copy of the attacking program.... and they spread, grew, took over more and more machines ....
What is an objective oriented example
Looks like a typing error to me.... but there is a langugae "Objective C".
What is an object oriented example
See todays reading!
What is the defference between quotes and daimond brackets in include statements
This
#include <iostream>starts search the compilers standard library for a file called "iostream".
The
#include "myFile.cpp"starts the search in the same directory as the file in shich you types the #include line. Only after filing to find it, does it search the standard libraries.
What exactly does the computer do with int counter = sqrt(n) when n is not a perfect square
Lets try
int counter = sqrt(17);
Notice this hard-to-remember fact: the expression on the right of '=' is evaluated the same way whatever the variable is on the left of the assignment. After the value is found it is made to fit the variable.
With nested for loops do you do the whole of the second loop inside the first one
Yes. If you see code like this
for(A; B; C)
for(D; E; F)
Gthen the sequence of events is like this
A; B; D; (E; G; F; E; G; F; ) !E; C
B; D; (E; G; F; E; G; F; ) !E; C
B; D; (E; G; F; E; G; F; ) !E; C
!B;
How do you get a program to pick a card at random
The function 'rand' is used in C++. All other languages
have a similar function. They work as random as it gets.
The book has a very good example of rand.
What are enumeration types
[ 14.html#5.8 Enumeration types ]
In what situations does having constant object benefit a programmer
When you have an object that must not, even by accident, change or mutate.
I didn't understand friends
They are for Thursday.
[ 18.html#8.3 Friends ]
What is the inheritance concept
This is part of CS202:
[ ../cs202/inheritance.html ]
How do objects oriented programming relate to data mapping
Interesting question.
First both data bases and OO are inspired by making the software reflect the real world. You can even use UML diagrams (with no operations) to describe a data base.
Second they have totally different theories. Most databases these days are "Relational" -- organized in tables connected by keys (values of attributes). In OOP we use the addresses (pointers) of data to connect and relate the objects.
There are some data bases that over some object-oriented features and so we may end up with a consistency between the two approaches.
Rich now, however, most OO prgrams has a special set of classes -- the persistance layer -- that know all about the data base the program uses but stops the other objects needing to know about the data base. This is deep stuff and we have several classes that touch on it.
. . . . . . . . . ( end of section Questions) <<Contents | End>>
Quiz 8 -- Program with a class and main
Lab 09 -- UML diagrams of Clock, Flight, Card, Cardstack, ...