Well...Is it possible for somebody to explain this a little more in detail and use general terms to clarify it? I am kind of confused with it. I have read a lot of explanations and stuff, but I still don't get it and hopefully somebody could help resolve my problem.
I'm guessing you are talking about classes and structs. A class or struct is a datatype that holds member variables and functions. I don't know if it is a good explanation but basically a class and a struct is a datatype that can be used to perform more advanced operations.
struct product {
int weight;
float price;
} ;
product apple;
product banana, melon;
We have first declared a structure type called product with two members: weight and price, each of a different fundamental type. We have then used this name of the structure type (product) to declare three objects of that type: apple, banana and melon as we would have done with any fundamental data type.
Once declared, product has become a new valid type name like the fundamental ones int, char or short and from that point on we are able to declare objects (variables) of this compound new type, like we have done with apple, banana and melon.
Right at the end of the struct declaration, and before the ending semicolon, we can use the optional field object_name to directly declare objects of the structure type. For example, we can also declare the structure objects apple, banana and melon at the moment we define the data structure type this way:
struct product {
int weight;
float price;
} apple, banana, melon;
It is important to clearly differentiate between what is the structure type name, and what is an object (variable) that has this structure type. We can instantiate many objects (i.e. variables, like apple, banana and melon) from a single structure type (product).
Once we have declared our three objects of a determined structure type (apple, banana and melon) we can operate directly with their members. To do that we use a dot (.) inserted between the object name and the member name. For example, we could operate with any of these elements as if they were standard variables of their respective types:
apple.weight
apple.price
banana.weight
banana.price
melon.weight
melon.price
This is what confused me. I have read it a lot and more than a couple of times but I still can't completely understand what they really are and sometimes for the type there is product banana and so forth but the second explanation does not include product and so....instead of using jargons for explanation, would somebody care to explain it to me in a more casual and simpler terms? The instructor's explanation is confusing as well.
Think of a struct (or class) as an object in life. in c++ (and life) objects have a name, which is a noun. Each object has a set of attributes that identify it from other objects, for example a red car is different than a blue car. Also, each object has a set of functions that it performs, which are referred to as methods or member functions in c++ and object oriented programming. In a struct, the same applies.
In your example you have a struct called Product (noun). It's attributes, which will make the product different than other products are it's weight and price. When you say:
1 2 3 4 5
struct Product
{
int weight;
float price;
};
You are setting up a general object with attributes. The object has no real name right now. In order to "create" multiple products or "instantiate" the product, you must state the following (the Product is now considered a data type):
Product apple;
this line simply says create a product called apple with weight and price attributes. You can then assign values to those attributes. Each time you instantiate a new object, say you wanted an apple, melon, and bananna, a separate set of variables are set aside for each so that all three products have different info, but the same types of variables.
Hope this is a little clearer, let me know if you're still confused.
I think it clears up a bit of my problem and confusion. You mean PRODUCT is just an object that has not been given a name yet but if we create a name apple for it, PRODUCT will become a structure and weight and price are the attributes of the apple that's different from other apples just like cars that have different types and a blue car is different from the a red car and both of them have different attributes or same attributes?
As you can see fromt he source codes, the first codes do include product as an structure for the objects apple, banana and melon but the second source codes only state apple, banana, and melon but doesn't include PRODUCT before or in front of the objects banana, melon and apple. I am a bit confused here. Same with class including function.
Declaring the objects after the closing brace of a struct is just another way of instantiating an object. The first and second code examples accomplish the same thing. I'm not sure if there is an advantage to one or the other, but I typically instantiate my objects stand alone, not at the closing brace of the struct.
Problem about English understanding. When you say instantiate an object, you just mean it is like declaring a variable right? At first, when my instructor say declare a variable...I thought he said something like ok there was something called variable...And now I seem to get used to what he said.
Back to the topic, when you said instantiate my objects alone, you mean the first source codes out of the quote:
product apple;
product banana, melon;
rather than the source codes within the quote with 4 numbers for each statement as the second codes?
sumbody plz he me out.i really dont know how to answer this
------------------
Before astronauts go up into space, they spend many hours in a spaceship simulator, a physical model of a space vehicle in which they can experience all the things that will happen to them in space. The spaceship simulator is a physical model of another object. A model can be thought of as a series of rules that describe the behaviour of a real-world system. We change the rules and watch the effects of these changes on the behaviour we are observing.
The technique that is used to make the model behave in the same way as the real object is called simulation. We can use similar techniques to build computer models of objects and events rather than physical models.
This project is concerning on building a general purpose simulation program that implements the basic concepts of data structures.
Problem:
Write a general-purpose simulation program that determines how long items (people, jobs, cars, etc.) must wait in line before being served. The program simulates a queuing system, using the following simulation parame¬ters: length of simulation, average time between arrivals, number of servers, and average transaction time.
The simulation must vary the number of servers and the time between arrivals of the items. By using new set of simulation parameters each time the simulation start, the practicality of the simulation to real life scenario is ensured.
You are required to state the program specification (functions, input, output, processing requirements, assumptions, and object oriented design) in your report. Add any figure, screenshot that you consider relevant using C++