• 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

According to my Java textbook, this is what Java was originally meant for, the JVM was supposed to make it easier to program things for a wide variety of architectures, but it never caught on in that domain. Somehow it caught on in other parts of tech.

A friend of mine does embedded tech and he does a lot of Java programming.
 

Onemic

Member
JS question here. How do you go about creating an array of objects? I have a student constructor and I want to create an array of students.

Also, how do I output to console without console.log automatically creating a new line? I want to print out all the properties within my student object, but on the same line.
 

Kalnos

Banned
JS question here. How do you go about creating an array of objects? I have a student constructor and I want to create an array of students.

Also, how do I output to console without console.log automatically creating a new line? I want to print out all the properties within my student object, but on the same line.

JSON.

JSON.parse() and JSON.stringify() will be worth a look.

Also, if you print a JSON object you will get what you want from console.log().
 

D4Danger

Unconfirmed Member
JS question here. How do you go about creating an array of objects? I have a student constructor and I want to create an array of students.

just make an array and put objects in it? JS doesn't do types.

Code:
var arr = []; arr.push(object);
Code:
var arr = [object, object, object];

is that what you mean?

Also, how do I output to console without console.log automatically creating a new line? I want to print out all the properties within my student object, but on the same line.

console.dir() will output on a single line that you can expand

console.log() can also take multiple arguments like console.log(a, b, c, d) and they will output on the same line
 

Onemic

Member
just make an array and put objects in it? JS doesn't do types.

Code:
var arr = []; arr.push(object);
Code:
var arr = [object, object, object];

is that what you mean?



console.dir() will output on a single line that you can expand

console.log() can also take multiple arguments like console.log(a, b, c, d) and they will output on the same line

JSON.

JSON.parse() and JSON.stringify() will be worth a look.

Also, if you print a JSON object you will get what you want from console.log().

Here's what my code looks like:
Code:
var person = {firstname: "", lastname: "", email: ""};
function Student(){};
Student.prototype = person;
student.prototype.sid = "";
student.prototype.courses = {};
var student = new Student;

I want to make an array of student objects, so that a user can input information into the above 5 properties multiple times and each time they input info it would be pushed into the next student object in the array
 

Godslay

Banned
Here's what my code looks like:
Code:
var person = {firstname: "", lastname: "", email: ""};
function Student(){};
Student.prototype = person;
student.prototype.sid = "";
student.prototype.courses = {};
var student = new Student;

I want to make an array of student objects, so that a user can input information into the above 5 properties multiple times and each time they input info it would be pushed into the next student object in the array

Just declare the array like the other poster displayed above:

var students = []; //You've made an array!
students.push(student); //Push a student object into the array.

Once the user creates a new student object and fills it with the properties, just push it into the array. Repeat as many times as necessary.
 

Onemic

Member
Just declare the array like the other poster displayed above:



Once the user creates a new student object and fills it with the properties, just push it into the array. Repeat as many times as necessary.

Here's my next issue though, how would I make it so that every time a user inputs info, a new student object is automatically created and that info pushed into that specific student object?
 

Godslay

Banned
Here's my next issue though, how would I make it so that every time a user inputs info, a new student object is automatically created and that info pushed into that specific student object?

I don't know how your specific project is set up, but it could create a button that says something like Create Student.

When clicked, it calls a Create Student function.

Inside that function instantiate a new Student object.

Prompt the user for the student id.

Prompt the user for the courses.

Store these values into the sid and courses.of that student object.

Push Student Object into Student Array.

Once the function completes the object should go out of scope, meaning that each time they push the create button, a fresh student object is created. Because of this you should create your array outside of this function so that it maintains the data inside the array, rather than being freshly created each time you click the button. If that makes sense.

Should be pretty simple code.

Something like this tied to a button click event, just quick and dirty but gives the idea:

var students = [];

function createNewStudent() {
var testStudent = new Student;
var sid = prompt("Enter student id");
var courses = prompt("Enter courses comma separated");

testStudent.sid = sid;
testStudent.courses = courses;
students.push(testStudent);
}

If you have everything set up right, you can then run your code, open the console type in the name of the students array and it should look something like this:

WSXMVei.jpg
 

Onemic

Member
I don't know how your specific project is set up, but it could create a button that says something like Create Student.

When clicked, it calls a Create Student function.

Inside that function instantiate a new Student object.

Prompt the user for the student id.

Prompt the user for the courses.

Store these values into the sid and courses.of that student object.

Push Student Object into Student Array.

Once the function completes the object should go out of scope, meaning that each time they push the create button, a fresh student object is created. Because of this you should create your array outside of this function so that it maintains the data inside the array, rather than being freshly created each time you click the button. If that makes sense.

Should be pretty simple code.

Something like this tied to a button click event, just quick and dirty but gives the idea:



If you have everything set up right, you can then run your code, open the console type in the name of the students array and it should look something like this:

WSXMVei.jpg

Thanks, that should do it perfectly
 

cyborg009

Banned
Is anyone here good with mySQL? I'm trying to create a trigger base on a column when it falls below a certain threshold but the logical is killing me.


Welp here is my code I needed the trigger to go off when it reaches a certain limit but I'm not sure how to go about it.

Code:
update Part 
set OnHand = 28
where PartNum = 'AT94'

drop trigger trg_lowThreshold

CREATE TRIGGER trg_lowThreshold 
ON Part After Update 
AS
BEGIN
			
			
			if exists(select 7 from inserted)
			INSERT INTO LowSupplyNotify
			(name,ManagerEmail,PartNum,NumberLeft)
			Select 
			'jk','jhjd',PartNum,OnHand
			From Inserted
			/*SELECT PartNum
			FROM Part*/

END
GO
 

Onemic

Member
Ugh, I hate asking questions here because I always think I have the dumbest questions, but I have another problem with my code. This time it's that for some odd reason the last property of my student object(an array of strings) refuses to be pushed into my students array and I have no idea why. using console.log on my student object shows that the array is indeed pushed into the courses property, but for some reason the property doesnt get pushed into the students array:

Code:
var person = { firstname: "", lastname: "", email: "" };
function Student(){};
Student.prototype = person;
Student.prototype.sid = "";
Student.prototype.courses = [];
var students = [];



var answer = null;
function getstudents(answer, students){
    var teststudent = new Student;
 
    for(var i = 0; i < answer.length; i++) {
        if (i < 4) {
            teststudent[i] = answer[i];
        }
        if(i > 3) {
            teststudent.courses[i-4] = answer[i];
            console.log("printing", teststudent.courses[i-4]); //string is pushed into courses array
        }

    }
    students.push(teststudent);
    console.log("printing array", students[0][4]); //shows up as undefined
}

function getanswer(string) {
    answer = string;
    return answer;
}



do {
    getanswer(prompt("Please enter your first name, last name, student ID, email and courses (seperated by ',')"));
    if(answer !== ""){
        var array = answer.split(',');
        answer = array;
        getstudents(answer, students);
    } else {
        answer = null;
    }
} while(answer !== null );
 
Maybe you just didn't copy-paste all of your code, but you seem to have an incomplete do-while loop at the end there (both the closing paren as well as the while statement are missing).

You should probably not have functions like getanswer (small nitpick: function names and variable names in JS are generally spelled in camelCase, not all lowercase) that return a value and modify global state at the same time. Makes it really confusing to read the code. Ideally you want to have as little global state (= variables that are accessible from every location in the code) as possible and your functions should be as self-contained as possible.

For example, getanswer modifies the global answer variable and also returns it. The return value is actually unused in your code. I'm pretty awful at JS and its scope rules, but I feel like that the fact that the variable name answer is used in different functions both as a function parameter and as a global variable (same for students) is causing you problems. Try to rewrite your code so you only have the students global variable. I think that'll help.
 

Ortix

Banned
I'm having some trouble with java again, the switch statement in particular.

I'm trying to use it to assign values to variables, for example:

chosenNumber = myscanner.nextInt();
switch (chosenNumber) {
case 1 : priceInteger = PRICE_ONE;
descriptionString = DESCRIPTION_ONE; break;
case 2: priceInteger = PRICE_TWO;
descriptionString = DESCRIPTION_TWO; break;
}
numberofitems = myscanner.nextInt()
System.out.println((descriptionString) + (" - total price = ") + (priceInteger * numberofitems))

But apparently my variables descriptionString and priceInteger have not been initialized. I assume this is because all of that I have done (or tried to do) in the switch statement, but these values aren't recognize outside of it. How do I solve this problem? :s
 

Husker86

Member
I'm having some trouble with java again, the switch statement in particular.

I'm trying to use it to assign values to variables, for example:



But apparently my variables descriptionString and priceInteger have not been initialized. I assume this is because all of that I have done (or tried to do) in the switch statement, but these values aren't recognize outside of it. How do I solve this problem? :s
Do you not have them initialized at the top of the class? You can initialize them as empty string and zero or something for the int.
 

Onemic

Member
Maybe you just didn't copy-paste all of your code, but you seem to have an incomplete do-while loop at the end there (both the closing paren as well as the while statement are missing).

You should probably not have functions like getanswer (small nitpick: function names and variable names in JS are generally spelled in camelCase, not all lowercase) that return a value and modify global state at the same time. Makes it really confusing to read the code. Ideally you want to have as little global state (= variables that are accessible from every location in the code) as possible and your functions should be as self-contained as possible.

For example, getanswer modifies the global answer variable and also returns it. The return value is actually unused in your code. I'm pretty awful at JS and its scope rules, but I feel like that the fact that the variable name answer is used in different functions both as a function parameter and as a global variable (same for students) is causing you problems. Try to rewrite your code so you only have the students global variable. I think that'll help.

Ya it was just a snippet of code. I added in the missing while statement at the end. Fixed up the problem I was having though, so thanks for the help guys.
 

Big Chungus

Member
is it possible to create a .bat script that will scan documents in windows 8?

trying to create the easiest method to scan documents for my mom without having her right click on the scanner in devices then messing around with the settings.
 

hateradio

The Most Dangerous Yes Man
is it possible to create a .bat script that will scan documents in windows 8?

trying to create the easiest method to scan documents for my mom without having her right click on the scanner in devices then messing around with the settings.
Is it difficult for her to use the Scan app? There appears to be a scanning app for Windows 8, who knew?

Otherwise, is Windows Fax and Scan also hard for her to manage? You can probably create an AutoIt script or something.
 
I have to use PHP for a group project. Any place where I can learn the basics and get going pretty fast? Anything specific I need to know about it?
 
Lol, I'm not too excited either. It's going to be a local front end for a database. Basic web framework stuff so people can interact with a picture or two.

I had asked last week because it was originally going to be in Python, but things change.
 

poweld

Member
Lol, I'm not too excited either. It's going to be a local front end for a database. Basic web framework stuff so people can interact with a picture or two.

I had asked last week because it was originally going to be in Python, but things change.

You could look at a WordPress plugin that uses a database for storage as a guide. For example, I used this recently: https://wordpress.org/plugins/rsvp/

It's not the best code, but looking at it should get you going.
 
You could look at a WordPress plugin that uses a database for storage as a guide. For example, I used this recently: https://wordpress.org/plugins/rsvp/

It's not the best code, but looking at it should get you going.

You could try http://www.codecademy.com/tracks/php.

Then download wamp (if you're using windows) and try making your own stuff.

Thank you for both of your answers. I don't know why I thought codecademy was lacking PHP.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
"." is used to access members of local objects.
"->" is used to access members of pointers to objects.
 

Husker86

Member
I got invited to sign up for Udacity's first nanodegree, Front End Web Developer.

I'm going to give it a shot. I'm slightly worried that I won't get more out of it than the free courses I've started (most recently discovered Udemy via StackSocial; I really like the offerings there).

At any rate, hopefully having some sort of a certificate I can put on LinkedIn might help me. Not sure that web development is exactly what I'm looking for as I personally prefer mobile app development, but my self-teaching has taken me through mobile, web dev and python and the like and they all seem to benefit from one another.

My current job in healthcare pays pretty well but has limited upward mobility and it's just not something I want to do forever. At the same time, I don't want to spend 4 years, or even 2 going through the traditional education route to get a degree in computer science; I feel that the majority of that time would be wasted with me learning things I already know.

I've read a lot of people on GAF post in threads that CS jobs are less reliant on traditional degrees since you can have a portfolio and prove what you know which is far more valuable. Hopefully that is true for me in the future!
 

Slavik81

Member
Just to make sure I'm not missing anything critical here. Is there any difference between . and ->?

Edit: c++
Code:
Dog* d = new Dog;
d->bark();
(*d).bark();

Both of the calls above are the same.

* is used to dereference a pointer. That is, it's basically a function that takes a pointer and retuens the object being pointed to.
. is used to access a member of an object.
-> dereferences the pointer it's used on and accesses a member on the resulting object. It's a combination of . and *.
 

hateradio

The Most Dangerous Yes Man
Can someone explain to me how to do permutation with an array of Strings?
Do you mean like using all the words in an array to build a set of new arrays?

Let's say {"Hey", "Okay", "No"} is an array, so a permutation it will give you { {"Hey", "Okay", "No"}, {"Hey", "No", "Okay"}, ...}?

I think you'd just do it the typical way, but instead of working on string and string indexes, you'll be working with an array.
 
I am writing a multithreaded program and I have been having a problem for the past few days. I have a text file that has 242 values that I have to retrieve and get the square root. I have no problem with that, I also have to identify on which line they appear on the text file and once again I have no issue getting that. My issue is that I have to have the threads run sequentially and divide the 242 between 4 threads.

Any help would be greatly appreciated.
 
Github now has a free student pack with all sorts of cool things. You just need a Github account and an accepted student email. Among other things, you get a free subscription for Unreal Engine 4, 100$ in credit for DigitalOcean (hosting service), private Travis CI builds and a Github Micro account.

https://education.github.com/pack
 

Atruvius

Member
Github now has a free student pack with all sorts of cool things. You just need a Github account and an accepted student email. Among other things, you get a free subscription for Unreal Engine 4, 100$ in credit for DigitalOcean (hosting service), private Travis CI builds and a Github Micro account.

https://education.github.com/pack

Great. I was thinking of sending my school an email about UE4 but now I don't have to! :D

I'm curious to see how UE4 compares to Unity.
 

Slavik81

Member
I am writing a multithreaded program and I have been having a problem for the past few days. I have a text file that has 242 values that I have to retrieve and get the square root. I have no problem with that, I also have to identify on which line they appear on the text file and once again I have no issue getting that. My issue is that I have to have the threads run sequentially a and divide the 242 between 4 threads.
Reading from the file is going to be squential anyways, so read all the lines before you split off into threads. Also, since you want your output to be ordered, you should do it all after the threads come back together. You'll need two global variables. One for the input data and one for the output data.

At the moment, your program might be multi-threaded, but you're constantly blocking on mutexes to do any operation. Only one thread actually is executing at a time... which sort of defeats the purpose of threading. If you make the above changes, you can make the calculations actually execute in parallel and then just do the sequential stuff before or after.
 
Great. I was thinking of sending my school an email about UE4 but now I don't have to! :D

I'm curious to see how UE4 compares to Unity.

You can create games in UE4 without every writing a single line of code. Its sort of like Unity + Playmaker, except you don't have to buy the visual scripting language separately.
 
How do you have your IDE set up with the colours and stuff? For a course I'm taking, we have to code via Linux (Ubuntu), so I have terminal set up as follows (white default text btw):

Q6ucRFh.jpg
 

Husker86

Member
I know almost everyone in this thread is probably past the point of needing Udacity, but I thought I'd give a quick update on their Nanodegree program.

In short, it is nothing like what I expected.

There are basically 5 (soon to be 7) projects. For example, in Project 1 they give you a PDF of a homepage and want you to recreate it with HTML/CSS. That's it. You can take their free courseware HTML/CSS class to learn what you need to accomplish the project, but there are no actual lectures in the nanodegree program.

Basically you are paying $200/month to be in the discussion community with fellow classmates and instructors, and to have your work inspected (and I assume commented on) by instructors.

That may not be a bad deal, but the actual learning part of the course consists of just links to their other courses that are available for free to anyone. Definitely not at all what I was looking for.

Oh well!
 

BreakyBoy

o_O @_@ O_o
How do you have your IDE set up with the colours and stuff?

I practically live in terminal at work. I also have a tendency to avoid IDEs and stick to plain editors as much as I can.

I use:
- zsh w/ zsh-syntax-highlighting w/ the Gozilla theme on Mac OS X/iTerm2 with the default profile's color scheme.
- Sublime Text 3 w/ the RailsCasts color scheme
- vim w/ Solarized Dark theme

I use the Inconsolata font on all of those, and practically anywhere else I work with code.

I know almost everyone in this thread is probably past the point of needing Udacity, but I thought I'd give a quick update on their Nanodegree program.

In short, it is nothing like what I expected.

We get plenty of newcomers in the thread. Not to mention that ongoing education is a big part of doing well in this field. So, this is definitely welcome info.

Basically you are paying $200/month to be in the discussion community with fellow classmates and instructors, and to have your work inspected (and I assume commented on) by instructors.

That may not be a bad deal, but the actual learning part of the course consists of just links to their other courses that are available for free to anyone. Definitely not at all what I was looking for.

That is disappointing, but I suppose it isn't much different than paying for a certification. You just get learning materials for free. Coursera seems to have started a similar "certified learning" system for some of its classes, but I think it's a lower one time fee per course. The courses are free, as they always have been, you just have to pay to authenticate/certify that you completed the coursework successfully.

How many months are you required to pay for to complete the nano degree?
 

survivor

Banned
I have a question regarding database design. So for the project I'm working on users are able to upload mp3 files. They are small in size, about 2-3MB and I expect to have about ~200 to start with. So I'm wondering what's the best way to store them? I'm thinking of either storing them as binary data into my MongoDB database or upload them to some audio directory and store paths to the files in the database. I'm leaning more towards the latter choice since it seems simpler, but I'm not sure what's the solution for this in the real world.
 
Reading from the file is going to be squential anyways, so read all the lines before you split off into threads. Also, since you want your output to be ordered, you should do it all after the threads come back together. You'll need two global variables. One for the input data and one for the output data.

At the moment, your program might be multi-threaded, but you're constantly blocking on mutexes to do any operation. Only one thread actually is executing at a time... which sort of defeats the purpose of threading. If you make the above changes, you can make the calculations actually execute in parallel and then just do the sequential stuff before or after.

Thanks I was able to get the output how I needed.

EDIT: Ugh, now not getting the output I needed.
 

Husker86

Member
How many months are you required to pay for to complete the nano degree?

I'm not sure if there is a minimum or not. All they have said is it should take an estimated 6-9 months with 10 hours/week minimum. That seems extremely overestimated, though I guess 10 hours/week really isn't that much.

However, the entire course pace seems to just depend on how much you already know. They only have the first five projects up now, so you may be at their mercy depending on how long it takes for them to post the last two projects.

Once you finish a project, the instructors look at it and give you a completion code if you meet all the criteria. They said their max turn-around time is 7 days but is usually much sooner.
 

BreakyBoy

o_O @_@ O_o
I wonder if it's possible just to pre-consume all the necessary courses and then grind through the nano degree coursework as fast as possible to minimize the cost.

Of course, you would need to know the course work needed before signing up.
 

Godslay

Banned
I have a question regarding database design. So for the project I'm working on users are able to upload mp3 files. They are small in size, about 2-3MB and I expect to have about ~200 to start with. So I'm wondering what's the best way to store them? I'm thinking of either storing them as binary data into my MongoDB database or upload them to some audio directory and store paths to the files in the database. I'm leaning more towards the latter choice since it seems simpler, but I'm not sure what's the solution for this in the real world.

Most of my projects use files on disk, paths in the database. There is a place for both for them, it just depends on your particular situation.

Here's some reading hope it doesn't confuse the situation.

http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay?page=1&tab=votes#tab-top
 
-Teach us C++ with current examples.
-Give us a book that utilizes C++11 features (which are welcome)
-Force us to code in C++98 with no header files.

How do you have your IDE set up with the colours and stuff?
Using Monodevelop to get used to an IDE. I'm making my own color scheme based off the Tomorrow-Night-Eighties scheme (which is fantastic).
 
Top Bottom