• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

usea

Member
I just took a job where the main language is Java. I'm going to miss C# and its features. I understand Java 8 has support for lambdas but no first class functions.
The way I code these days, I'd kill myself dropping C# for Java. I use Func and lambdas everyyyywhere. :( sorry
 

hateradio

The Most Dangerous Yes Man
These and Scala (Lift). Java (JEE) and C# (.NET) are the historic players but if you are starting from scratch today I'd look at the first three. Also, fuck PHP.
I had never heard of Lift only Play, which looked very Rails-y. I kinda want to develop a site using Scala, so I'll look into it, too.
 

Zoe

Member
I'd say skip PHP and jump right into C#, ASP.NET, either MVC or Webforms. I know some will laugh at webforms, but like Hanselman says webform developers are the dark matter of the web. Plus you get the benefit of working with VS, and Entity Framework. Also, emmet is awesome if you have web developer tools installed.

Definitely go for MVC if you have a choice between the two, but familiarize yourself with a bit of webforms for legacy stuff.

(Stupid SSRS...)
 

d[-_-]b

Banned
Thanks Hugh for trying to help turns out i'm retarded it was such a simple error, I was using the wrong table... project_users vs projects_users
 

Godslay

Banned
Definitely go for MVC if you have a choice between the two, but familiarize yourself with a bit of webforms for legacy stuff.

(Stupid SSRS...)

I'd argue one should really know both to some degree. Webforms aren't 'legacy' necessarily. Plenty of new projects are created using webforms, even moreso than MVC currently I'd guess. Probably won't change for awhile considering most places are going to leverage their existing code base.
 

usea

Member
I would never choose to use webforms, and I wouldn't take a job doing them either, unless it paid an absurd amount, which it wouldn't.
 

Korosenai

Member
Hmmm i've been stuck on this for a couple days now and I really can't find a solution.

I'm creating a c++ program where I have to read id's and grades from a file. Each id can be listed more than once (ex.):

Code:
1001 65
1001 75
1002 80
1002 90
1002 85
1003 70

Then for each id, I have to find the id's minimum, maximum, and average for its grade (ex.):

Code:
1001 65 75 70.00
1002 80 90 85.00
1003 70 70 70.00

This is where the problem starts. I have no idea how to write the code to where, for example, as long as id = 1002, it will then stay on id and calculate min, max, and avg. Then once it is no longer id 1002, display the min, max, and avg and then move onto the next id doing the same thing.

Should I use nested loops? Should I put either id or grade into an array? I've tried nested loops to where the first loop will read the id and the grade from the file, then the second loop, as long as id = currentid, find the min, max, and avg while reading in another id and grade until id no longer = currentid, thus ending the loop.

As I said i've been stuck on this for a while now and I just have no idea how to implement the code. We've just started pointers as well, so that's about as much knowledge of c++ as I know (which is arrays, functions, loops, files, strings).
 

nan0

Member
I'm not a C++ guy, but you could e.g. either make a multidimensional array (ID as identifying element, and then a field each for min, max, avg and number of values added), or a custom class with variables for the same fields plus an array or some kind of list or map to store the objects of this class.
 

Water

Member
I'm creating a c++ program where I have to read id's and grades from a file.
...
I've probably said this before, but a C++ class that teaches C-style arrays and pointers to total beginners is bad. Bad. At the very least, they should have taught you to use std::vector first. This is a very easy thing to code if you are using the proper tools, but the solution is either going to be ugly or pretty complicated if you don't have the proper tools. If you aren't explicitly prohibited from using the proper library stuff, right now is the time to learn it.

A solution to your problem that is actually reasonable would read the file line by line, and for each new id, make a new entry in a std::map that is indexed by the id and contains the current min, max, the number of grades and the sum of grades. If that id's entry already existed, it would just increment the number of grades and add to the sum of grades. Afterwards you'd loop through the std::map and print everything.

For one kind of ugly hack to get this done without using any proper data structures, you could read the file once just to determine the number of lines, then reserve an array of that size (because that's the maximum you need if every id happens to be unique) where every entry has room for those same five numbers, and then read the file again. You could then do essentially the same as above, but horribly inefficiently; for every line you read, check if that id is already in the array and act appropriately.
 

Zoe

Member
I'd argue one should really know both to some degree. Webforms aren't 'legacy' necessarily. Plenty of new projects are created using webforms, even moreso than MVC currently I'd guess. Probably won't change for awhile considering most places are going to leverage their existing code base.

I meant legacy more for stuff that isn't supported in MVC such as report parts. Most things you want to do in webforms, at least stuff that I have come in contact with, can be done with MVC.
 
d[-_-]b;83873807 said:
Thanks Hugh for trying to help turns out i'm retarded it was such a simple error, I was using the wrong table... project_users vs projects_users

Heh, this should have been the first thing to check when you posted the table definition. My bad. :)
 

Slavik81

Member
Code:
baseClassPointer = new DerivedClass();
(dynamic_cast<DerivedClass*>(baseClassPointer))->derivedFunction();
whywouldyoudothat.png
 
Webforms aren't bad. The code written in webforms is bad.

Full disclosure: I work in webforms.

Every app I've seen in webforms is the same case of people having terrible separation of concerns, too much code in the codebehind, lots of repeated code, bad OO. Very procedural. But I don't blame webforms on that, it's just people that aren't very experienced being asked to do too much.
 

Water

Member
Code:
baseClassPointer = new DerivedClass();
(dynamic_cast<DerivedClass*>(baseClassPointer))->derivedFunction();
whywouldyoudothat.png
Well, you want to make a new DerivedClass, right? And "new" is how you make new things, at least that's how it was in Java, and it compiles so it's probably good here too.

Then, if you've read some fancy C++ tutorial on the internet, you know you can put a DerivedClass into a BaseClass pointer. Why not? After all, you might need to put some other class there later, and there doesn't seem to be an "Object" in C++ that would be even more general. Flexible design, the hallmark of good coding!

The second line is some next-level shit. You want to call the DerivedClass function and the compiler is complaining, but you know how to "cast" things like a boss, so no problem. And then, because you care about code style and good practices, you go the extra mile and use a C++ cast instead of the old C-style cast. Exquisite.
 

The Technomancer

card-carrying scientician
Hm, need a spot of help. My controls class is doing stuff like bitwise logic and shifting and I can't figure out why my binary printing function isn't working:
Code:
void bitprint(int toprint){
	int filter = 0x80000000, printer  = 0x00000000;
	for(int i = 0; i < 32; i++){
		printer = toprint & filter;
		if(printer = 0x80000000){
			printf("1");
		}
		else{
			printf("0");
		}
		toprint<<1;
	}
}

I've been stepping through it and for whatever reason toprint<<1 isn't actually shifting the value

EDIT: just noticed I forgot the damn ==. Still doesn't explain why toprint isn't shifting though

EDIT2: Huh...a lot of places on the internet seem to neglect to mention that if you want the shifting to actually effect the variable in question you need to do it as <<=
 

poweld

Member
It's not mentioned because there are no operators which change the value other than postfix and prefix increment and decrement. Other than those operators, you can assume that no (default) operators will modify the value being operated upon.
 

nan0

Member
EDIT2: Huh...a lot of places on the internet seem to neglect to mention that if you want the shifting to actually effect the variable in question you need to do it as <<=

Well, it's the same as += or *= if you want to alter the value in place. Or you use toprint=toprint<<1.
 

usea

Member
Technomancer, "toprint<<1" is an expression. It evaluates to some result, but you have to assign that result to a variable if you want to keep it around. It's like saying "x+1". That doesn't increase x by 1, it evaluates to x+1, which has to be assigned or tested to be useful. It's not useful by itself, and I'm surprised whatever language isn't giving you an error for having that expression by itself.
 
I'm currently in college focusing on programming. I'm pretty good in Java and this term I am learning C, data structures in Java, and some assembly language. Trying to wrap my mind around what goes on the stack and what goes on the heap, references to variables, etc. I'm having fun with it though.

Also, the book my college uses for Java is "Java How to Program (9th ed)" by Deitel and Deitel, which I find just OK.
 
Hm, need a spot of help. My controls class is doing stuff like bitwise logic and shifting and I can't figure out why my binary printing function isn't working:
Code:
void bitprint(int toprint){
	int filter = 0x80000000, printer  = 0x00000000;
	for(int i = 0; i < 32; i++){
		printer = toprint & filter;
		if(printer = 0x80000000){
			printf("1");
		}
		else{
			printf("0");
		}
		toprint<<1;
	}
}

I've been stepping through it and for whatever reason toprint<<1 isn't actually shifting the value

EDIT: just noticed I forgot the damn ==. Still doesn't explain why toprint isn't shifting though

EDIT2: Huh...a lot of places on the internet seem to neglect to mention that if you want the shifting to actually effect the variable in question you need to do it as <<=

It seems like you're programming this in C. For easier debugging, use
Code:
-Wall -Wextra
in your compiler command line options and look at the warnings (-Wall is for enabling all warnings, -Wextra is for even more warnings). A lot of them are not very important like unused variables or parameters but for your code, I get following warnings from clang:
Code:
test2.c:7:14: warning: using the result of an assignment as a condition without
      parentheses [-Wparentheses]
                if(printer = 0x80000000){
                   ~~~~~~~~^~~~~~~~~~~~
[...]
test2.c:13:11: warning: expression result unused [-Wunused-value]
                toprint << 1;
                ~~~~~~~ ^  ~


In other languages, something like
Code:
if(printer = 0x80000000)
won't even compile but C is a lot more lenient, for better or worse.
 

leroidys

Member
I'm currently in college focusing on programming. I'm pretty good in Java and this term I am learning C, data structures in Java, and some assembly language. Trying to wrap my mind around what goes on the stack and what goes on the heap, references to variables, etc. I'm having fun with it though.

Also, the book my college uses for Java is "Java How to Program (9th ed)" by Deitel and Deitel, which I find just OK.

Yeah assembly was the hardest thing to wrap my mind around. I think a lot of it was because I was learning C at the same time - which it sounds like you are doing as well. Now that I have a good knowledge of C and a ton of experience debugging it, I feel like it would be a lot easier. All I can say is "good luck!"
 

leroidys

Member
So my girlfriend is trying to build a really simple website for her business. I think she could learn html pretty quickly, but otherwise has no programming experience. Can you guys recommend any good software or resources? Preferably for mac.
 

Zoe

Member
So my girlfriend is trying to build a really simple website for her business. I think she could learn html pretty quickly, but otherwise has no programming experience. Can you guys recommend any good software or resources? Preferably for mac.

People will poopoo on this, but Dreamweaver is good for beginners who want to see the syntax and output side by side.
 
Hello. A couple of questions for java pros. I'm currently building a Tank program for my Graphics/OOP course and I'm sort of stuck on a few things.

The prompt says to build an Game area of 1024x1024. I'm assuming that I should just use a char array [][] or a vector. Somewhat confused on this.

Another thing that I'm stuck on is Location and the Point class. If anyone can link any tutorials for that, it'd be a great help. I'm thinking that I'd probably make my Game area of 1024x1024 Points instead.

The last thing I'm stuck on is removing an object from an ArrayList of Objects in a method that references another class.

For example

Code:
class GameWorld {
  Tank playerTank = new Tank(10,10); // life and missileCount
  private ArrayList<GameObject> GameObjectList = new ArrayList<GameObject>();
  class GameObject
  { 
   // ... 
  }
  class Tank extends GameObject implements another class
 {
  // tank life and missileCount
 }
}

 public class Game {
  public Game()
  {
   gw = new GameWorld();
   removesomething();
  }
  public void removesomething()
  {
    // find a way to remove a object from the arraylist and the game.
  }
}
 
Okay, so I'm working on a sorted linked list but instead of manually creating variables and then adding it, I wanted to make a simple user interface so I can add it when I run the program. The create takes a void pointer and the list. So inside my switch in main:
x is a void pointer, num is an int.
Code:
case 2:
			scanf("%i",&num);
			x=&num; /*I even tried casting it with (void*)*/
			insert(list,x); 
			break;
Say I insert 5 first and then 10. I keep getting 10, 10 when I print the list...yet when I manually added them with different void variables, I get 10, 5. I tried doing insert(list,(void*)&x); and I keep getting the same thing. Someone, help a nub in C. :( If not, I'll just create new void and int variables and assign the ints to the void pointer with a void cast...
 

tokkun

Member
Okay, so I'm working on a sorted linked list but instead of manually creating variables and then adding it, I wanted to make a simple user interface so I can add it when I run the program. The create takes a void pointer and the list. So inside my switch in main:
x is a void pointer, num is an int.
Code:
case 2:
			scanf("%i",&num);
			x=&num; /*I even tried casting it with (void*)*/
			insert(list,x); 
			break;
Say I insert 5 first and then 10. I keep getting 10, 10 when I print the list...yet when I manually added them with different void variables, I get 10, 5. I tried doing insert(list,(void*)&x); and I keep getting the same thing. Someone, help a nub in C. :( If not, I'll just create new void and int variables and assign the ints to the void pointer with a void cast...

You are not showing all the code that matters, but from your description, I can guess.

You are passing the address of 'num' every time. The scanf changes the value of 'num', not its address. Therefore every time you insert, you are gong to pass the exact same value for 'x' (the address of 'num'). Every element you insert in your list will have the value of the address of 'num'. The value pointed to by all of those pointers will always be the current value of num.

Some suggestions:
-Consider whether it is really a good idea to store void pointers in your list. If the goal is to make list store a generic data type, consider using a template instead of a void pointer.
-If you are set on storing pointers, you need to create a unique pointer for each element:

Code:
  ...
  int* new_element = malloc(sizeof(int));
  *new_element = num;
  insert(list, (void*)new_element);
  ...

You must also remember to free these pointers when you remove them from the list.
 
So my girlfriend is trying to build a really simple website for her business. I think she could learn html pretty quickly, but otherwise has no programming experience. Can you guys recommend any good software or resources? Preferably for mac.
Does she want to program it herself? Because there is an alternative which is basically installing something like joomla on a web server, getting a template (or using one of the defaults) then basically just typing up the stuff that needs to be on the site. I've used it before and you can basically learn all that you need to about using it in an hour of playing around. Sure its not programming, but for someone who wants to just get up and get a professional looking website without much work its pretty amazing.

Otherwise, check out The New Bostons html+css videos.
 
You are not showing all the code that matters, but from your description, I can guess.

You are passing the address of 'num' every time. The scanf changes the value of 'num', not its address. Therefore every time you insert, you are gong to pass the exact same value for 'x' (the address of 'num'). Every element you insert in your list will have the value of the address of 'num'. The value pointed to by all of those pointers will always be the current value of num.

Some suggestions:
-Consider whether it is really a good idea to store void pointers in your list. If the goal is to make list store a generic data type, consider using a template instead of a void pointer.
-If you are set on storing pointers, you need to create a unique pointer for each element:

Code:
  ...
  int* new_element = malloc(sizeof(int));
  *new_element = num;
  insert(list, (void*)new_element);
  ...

You must also remember to free these pointers when you remove them from the list.
That's what I figured was going on. Yeah, it's a generic link list so since I can't really do it without creating a new pointer, I'll pass on adding the user interface this time around and get back to it when I have the time to play around with it. Thank you.
 
I'm having to write a program in C and I keep getting this error
Code:
main.c:38:6: error: expected identifier or ‘(’ before ‘=’ token
It's creating some serious problems but I can't find what's throwing the error. Here's my header file:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

typedef struct user_cmd{
        char* name;
        char* value;
}*set;
struct user_cmd *alias;

static const char* default_commands[5] = {"set","tes","alias","saila","exit"};
And the little bit of code leading up to the error:
Code:
#include "main.h"

extern bool check_cmd(int argc, char** argv, struct user_cmd** set, struct user_cmd** alias);
void user_input(int argc, char** argv);


int main(int argc, char* argv[]){

        if(argc != 1){
                printf("Entering shell with arguments.\n");
        }
        else{
                printf("Entering shell with no arguments.\n");
        }

        user_input(argc, argv);

        printf("Bye bye!\n");

        return 0;
}

void user_input(int argc, char** argv){

        int i = 0;
        bool exit_cmd = true;
        bool buffer_exit = true;
        char buffer;
        char** argument;

        argument = malloc(sizeof(char));
        *argument = malloc(sizeof(char));

        set = malloc(sizeof(struct user_cmd));
        alias = malloc(sizeof(struct user_cmd));
Anybody with better eyes and understanding able to help?
 
I'm having to write a program in C and I keep getting this error
It's creating some serious problems but I can't find what's throwing the error. Here's my header file:


And the little bit of code leading up to the error:

Anybody with better eyes and understanding able to help?

"set" is a type.

Code:
[B]typedef [/B]struct user_cmd{
        char* name;
        char* value;
}*[B]set[/B];

While here

Code:
set = malloc(sizeof(struct user_cmd));

you are using it as a variable.
 
"set" is a type.

Code:
[B]typedef [/B]struct user_cmd{
        char* name;
        char* value;
}*[B]set[/B];

While here

Code:
set = malloc(sizeof(struct user_cmd));

you are using it as a variable.
Thank you for the help, that fixed the problem. I was told by my professor that we should always use typedef when defining a struct so I guess I need to go read up on typedef.
 

iapetus

Scary Euro Man
So my girlfriend is trying to build a really simple website for her business. I think she could learn html pretty quickly, but otherwise has no programming experience. Can you guys recommend any good software or resources? Preferably for mac.

If she wants the site to look remotely professional, she should look at getting it professionally designed. Nobody who has just learned HTML is going to make a good looking website. The other cheap option is to use one of the standard pieces of CMS software out there, but even that's likely to look a bit ropey.
 

jokkir

Member
Can someone help me understand this. I'm creating an object from a class but the argument sent to it is a &cout. For example:

Code:
int main(){
	ClassOutput outp(&cout);
	outp << "Sent to Memory Stream" << endl;
	outp << "Line 2 of Sending to memory stream" << endl;
	cout << "Counter of how many strings in outp" << outp.getCount() << endl;
	cout << "The sum of all characters in outp" << outp.getCheckSum() << endl;

        return 0;
}
How would the constructor look like exactly when the &cout is sent to the class? And what would the basic outline of the class look?

I think I have a general idea of what to do but I'm a bit confused. Also, if you know any online resources that cover this that would help out a lot

/disregard
 

leroidys

Member
If she wants the site to look remotely professional, she should look at getting it professionally designed. Nobody who has just learned HTML is going to make a good looking website. The other cheap option is to use one of the standard pieces of CMS software out there, but even that's likely to look a bit ropey.

It's mainly for employees or occasionally already-customers, and functionally it basically just needs to be a gussied up dropbox.

Thanks for the suggestions so far all, let me know if any other software comes to mind :)
 

jokkir

Member
Okay, disregard my last post since I think I know what I'm doing now.

I have a question though since I'm not exactly sure why it's giving me a "cout undeclared identifier" error.

So my main has the following:

Code:
MainOutput main(&cout);

And in my header/implementation file, I have:
Code:
MainOutput& operator<<(const char* str){
		//code
		return *this;
	}

	MainOutput& operator<<(double d){
		//Code
		return *this;
	}

Basically I'm trying to put stuff in my memory stream so I can count a number of characters in that stream. By overloading the << I try to make it so that it can I can do those calculations within the brackets.

Anyone know why I'm getting this error though?
 
Okay, disregard my last post since I think I know what I'm doing now.

I have a question though since I'm not exactly sure why it's giving me a "cout undeclared identifier" error.

So my main has the following:

Code:
MainOutput main(&cout);

And in my header/implementation file, I have:
Code:
MainOutput& operator<<(const char* str){
		//code
		return *this;
	}

	MainOutput& operator<<(double d){
		//Code
		return *this;
	}

Basically I'm trying to put stuff in my memory stream so I can count a number of characters in that stream. By overloading the << I try to make it so that it can I can do those calculations within the brackets.

Anyone know why I'm getting this error though?

You have included iostream? Are you "using" the namespace "std"?
 

jokkir

Member
You have included iostream? Are you "using" the namespace "std"?

I included that and it works but the assignment in the main, the professor didnt include that in the main file. I'm not sure if it should be added or what :\ I guess I'll ask him next class.
 
Stuck on a few things for my Tank program. How would you build a GameWorld map of 1024x1024x without using arrays or vectors. I already put accesors/mutators in order to call methods from one class to another and is still blank on how to use location classes for my program.
 

Water

Member
Stuck on a few things for my Tank program. How would you build a GameWorld map of 1024x1024x without using arrays or vectors. I already put accesors/mutators in order to call methods from one class to another and is still blank on how to use location classes for my program.
- Is there a reason you don't want to use arrays or vectors?
- What are you actually trying to do with the map? This is a critical question you have to answer if you are to make any intelligent decisions regarding how to code it. For instance: does the 1024x1024 map consist of tiles that are either passable or impassable, or are there other map features? Can the tiles change during play? How many entities (I'm assuming these are called "tanks") are there roaming around on the map? Are there some calculations you need to run often, like testing whether tanks see each other, finding closest tanks within X range, etc.?
 
professor said not to use arrays or vectors. yeah it's a map where there are movable objects such as tanks and immovable objects such as trees and rock. they all spawn at random positions cannot hold the same location. if they hold the same location, they are removed from the game. there's quite a few functions that i need to check but i already implemented them in.
 

iapetus

Scary Euro Man
It's mainly for employees or occasionally already-customers, and functionally it basically just needs to be a gussied up dropbox.

Thanks for the suggestions so far all, let me know if any other software comes to mind :)

Then take a look at Joomla, Drupal and the like. They may provide the functionality she's looking for, and one of the standard skins should fit the requirements in terms of markup. Most web hosts these days support them as an automatic install.
 
professor said not to use arrays or vectors. yeah it's a map where there are movable objects such as tanks and immovable objects such as trees and rock. they all spawn at random positions cannot hold the same location. if they hold the same location, they are removed from the game. there's quite a few functions that i need to check but i already implemented them in.

That seems very weird. It's in Java, right? Did you get any hints on what else you should use? Because for a fixed-size game map, a two-dimensional array seems like the most obvious solution.
 

jokkir

Member
Hopefully one more question for me for the time being :p

I have to design and create a class that will act as a buffer before outputting to the user. I have to overload the << operator and store the values that were to be displayed in that buffer then do calculations that will count how many characters are to the right of the << and get the arithmetic sum to become the "checkSum". However, I have a problem with overloading<< with int variables. Here's my code:

Code:
MainOutput& MainOutput::operator<<(int i){
	std::stringstream ss;
	ss << (char)i; //So it can cast the 'z' and endl characters to the ASCII decimal value

	count += ss.str().length();
	
	for(int i = 0; i < ss.str().length(); i++){
		checkSum += (int)ss.str()[i];
	}
	return *this;
}

And the main will consist of:
Code:
double d1 = 12.3;
int i1 = 45;

mainout << "d1=" << d1 << " i1=" << i1 << 'z' << endl;

The line should give a count of 14, I think.

However, the problem I have is that it makes the i1 variable (with the value of 45) back to the ASCII character "-". I know it has to do with the casting of int i to a char but that's the only way I found to change the 'z' back from ASCII value 122 to "z" (and only one character count) and to detect endl characters as only one character.

Anyone know how I can fix this?
 

Water

Member
professor said not to use arrays or vectors. yeah it's a map where there are movable objects such as tanks and immovable objects such as trees and rock. they all spawn at random positions cannot hold the same location. if they hold the same location, they are removed from the game. there's quite a few functions that i need to check but i already implemented them in.
Okay, so there can't be more than one object per map location ever; that is a very important fact to notice when you are choosing a data structure. There's still at least one key piece of information you haven't told us: how many tanks/trees/rocks can there be on the map at any given time? (If there isn't a hard limit, explain how exactly they get spawned, including any random probabilities.)

The naive solution would be to just use a huge array; 1024x1024 is not large enough that you'd actually have to do something else. If it were possible for the whole map to be filled with objects, it would probably be wise to use an array here. If your professor explicitly forbids it, it seems he wants to force you to use something you were recently taught. Have you been taught anything about performance or memory consumption in general? TreeMaps? HashMaps? Other data structures?
 
That seems very weird. It's in Java, right? Did you get any hints on what else you should use? Because for a fixed-size game map, a two-dimensional array seems like the most obvious solution.


Okay, so there can't be more than one object per map location ever; that is a very important fact to notice when you are choosing a data structure. There's still at least one key piece of information you haven't told us: how many tanks/trees/rocks can there be on the map at any given time? (If there isn't a hard limit, explain how exactly they get spawned, including any random probabilities.)

The naive solution would be to just use a huge array; 1024x1024 is not large enough that you'd actually have to do something else. If it were possible for the whole map to be filled with objects, it would probably be wise to use an array here. If your professor explicitly forbids it, it seems he wants to force you to use something you were recently taught. Have you been taught anything about performance or memory consumption in general? TreeMaps? HashMaps? Other data structures?

Here's the response to my question from my professor

First, I'm not sure what you mean about choosing between a Vector and a Array of doubles. The value "1024" is simply the maximum value that an object's coordinates may have. If you are thinking about something like declaring a huge 1024x1024 array, or vector, that has one location for every place in the world, that's the wrong approach. You cannot create a separate location for each position in the world because, as the assignment says, we will be changing the size later. Specifically, we will change the size to be the largest number in the machine. That prohibits creating an array; there's not enough memory to hold the array.

So far we learned just basic OOP ideas like inheritance, polymorphism, abstraction and interfaces.

And there is no limit to how objects get spawned, as long as they don't occupy the same space at the beginning. Here's the basic pseudocode:

Code:
   Get user input for how many tanks, rocks, trees to be spawned
 
	 // do a for loop for how many tanks user wanted
	 	/*
	 	 	for (int i = 1; i < num_Tank; i++)
	 	 	{
	 	 		Tank enemyTank(number) = new Tank(10, 10); // build tanks
	 	 		put random location
	 	 		check if location isn't taken
	 	 		put into gameobjectlist
	 	 	}
	 	 */

and so on.
 
Top Bottom