|
| |||||||
| http://www.narutomania.com/forums/New Month, New Problems |
| For these forums to remain up we need $480 within 7 days. Please donate HERE br> br> We need this amount no matter what to keep this website up. Thank you for your support. |
![]() |
| | Thread Tools |
15-02-2008, 02:14 PM
| #1081 |
| Donator |
Yes, arguments always must have types.
|
| |
19-02-2008, 05:13 AM
| #1082 |
| Chuunin Join Date: Apr 2007
Posts: 334
My Mood:
Rep Power: 0 ![]() |
im in a photography class and im shooting some metallic objects. the glare on them is really bad anyone know a way to get rid of that without losing proper lighting.
|
| |
20-02-2008, 04:39 AM
| #1083 |
| Akatsuki |
Write an array-based implementation for the ADT sorted list, · Use a class for the implementation. · Use a typedef to make it easy to change the kind of items stored in the list. · Do not use any STL data structure facilities in your implementation. In particular, use arrays, not vectors. · Note that the ADT has positions 1, 2, 3, etc. while a C++ array has indices 0, 1, 2, etc. The user of your class acts as if he or she is working with the ADT and must be able to treat position 1 as the first position, regardless of the details of your implementation. Do use indices starting from 0, but hide this implementation detail from the user. · Make sure sample runs illustrate all of the functionality of your class. As always, output should be commented to indicate what’s being tested in each part of each run. · Ideally, your implementation should allow the list to store any number of items, but you’re likely to find this hard. Work first toward a version that allows up to a fixed maximum number of items. If you have time after that’s operational, see if you can figure out how to get the size of the array to expand as necessary so that there’s no limit to the number of items that can be stored.
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
26-02-2008, 02:30 AM
| #1084 |
| Akatsuki |
two questions, What's typedef, and Since I'm using a class, vectors would have been easy for me. Since I can just make a private data member a vector. But I have to use an array. I'm not sure what to do here, how can I combine an array with a class? I think that's the question I'm asking.
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
26-02-2008, 04:51 AM
| #1085 | |
| Genin | Quote:
Take this example: #include <iostream> using std::cout; int main(){ typedef int Grade; // letting Grade acts as an integer to have more descriptive name Grade exam1=100; Grade exam2=80; cout << "Your grade for exam1: " << exam1; cout << "\nYour grade for exam2: " << exam2; return 0; } This simple program will output: Your grade for exam1: 100 Your grade for exam2: 80 You can check wikipedia for more details: typedef - Wikipedia, the free encyclopedia Last edited by ahme; 26-02-2008 at 04:54 AM. | |
| |
26-02-2008, 04:58 AM
| #1086 |
| Chuunin |
Give an example of a function f that is continuous on R but for which f(R) is bounded, open interval. R = set of all reals
__________________ |
| |
26-02-2008, 09:28 PM
| #1087 |
| Administrator |
f(x) = -ex for all x in R. lim[x->-infinity]( f(x) ) = lim[x->-infinity]( -ex ) = lim[x->infinity]( -1 / ex ) = 0 lim[x->infinity]( f(x) ) = lim[x->infinity]( -ex ) = -infinity f(x) is continuous on R and is bounded because 0 > f(x) for all x in R. Also, f(x) lies on the open interval (-infinity, 0).
__________________ |
| |
26-02-2008, 09:36 PM
| #1088 |
| Akatsuki |
I'm not sure if this is correct. Let say I have a class, can I say in the private private: int x[20]; Where we have a class that has an array of x, with 20 max, as it's private data member?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
26-02-2008, 11:40 PM
| #1089 | |
| Donator | Quote:
The reason they asked you to use typedef is so that you can easily change what your array stores. So at the top of you file you should have something like Code: typedef int MyType; Then declare your array like Code: MyType contents[]; Then, you can easily change the typedef to something like Code: typedef float MyType; | |
| |
27-02-2008, 03:02 AM
| #1090 |
| Akatsuki |
I'm still not sure why we need typedef. because it's the same as int a[20], a is an array of ints right?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
27-02-2008, 04:23 AM
| #1091 | |
| Donator | Quote:
Well, your class might have something like Code: private:
int a[20];
int numElements;
public:
int elementAt(int index) {
return a[index - 1];
}
void addElement(int element) {
a[numElements] = element;
numElements++;
}
Code:
typedef int ArrayType;
private:
ArrayType a[20];
int numElements;
public:
ArrayType elementAt(int index) {
return a[index - 1];
}
void addElement(ArrayType element) {
a[numElements] = element;
numElements++;
}
| |
| |
27-02-2008, 04:33 AM
| #1092 |
| Akatsuki |
I get that...I still don't know why we have to use it. It's not really doing anything efficient...it's just time-saving I guess...but this is just schoolwork.
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
27-02-2008, 04:39 AM
| #1093 |
| Donator |
Haha, well yes in terms of what is generated by the compiler it literally makes no difference, the compiler's going to replace the typedefs anyway. However, if you do end up coding for a living, appropriate use of typedefs will be required. Code that is easy to maintain and adapt has a very real monetary value. |
| |
28-02-2008, 02:04 PM
| #1094 |
| Akatsuki |
So in my class. typedef int myArray class private: myArray = anArray[20] Now should I create a random number code, that will then be stored into the Array, or do I put a code in the main, asking the user to input 20 numbers?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
28-02-2008, 04:37 PM
| #1095 | |
| Donator | Quote:
That should be: Code: typedef int MyArray; private: MyArray anArray[20]; The assignment doesn't say, so you can probably do either way. I think using random numbers is preferrable, so that when you are testing this you don't have to keep typing stuff in. | |
| |
29-02-2008, 12:02 AM
| #1096 |
| ANBU Join Date: Oct 2006
Posts: 1,309
Rep Power: 0 ![]() |
you basically use typedef to hide your implementation, from the client, its just a good principle of programming.so that you can change your data without bothering the client.
|
| |
29-02-2008, 01:52 AM
| #1097 |
| Akatsuki |
How would I put in random numbers into my array?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
29-02-2008, 03:42 AM
| #1098 |
| Donator |
Well, they don't have to be randomly generated, it looks to me. Your teacher just wants you to demonstrate the functionality of the class. So you can just have a main function that calls your add function a bunch of times with whatever numbers you want, and then retrieves elements and prints them.
|
| |
29-02-2008, 04:31 AM
| #1099 |
| Akatsuki |
what would that accomplish?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
29-02-2008, 04:41 AM
| #1100 |
| Donator |
You're just supposed to show that your class works. Insert a bunch of stuff, then print it out and show that they are in order now.
|
| |