• 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

iapetus

Scary Euro Man
Im back again with license woes.

Trust me, you don't know what licensing woes are.

At a company I worked for, we used some code under the JSON license. Which is a really simple license:

Copyright (c) 2002 JSON.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The Software shall be used for Good, not Evil.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Eventually our legal team spotted this - specifically the bolded part. And they got nervous because they weren't sure they could guarantee customers of our product might not do evil with it, and they didn't know what 'evil' meant anyway (hey, lawyers...)

So I was the developer asked to contact the author of the code and effectively ask him for a license to use his software for evil. Needless to say we didn't get it, and we had to rewrite that code shortly after.

Although apparently, he did offer that license to someone else:

About once a year, I get a letter from a lawyer, every year a different lawyer, at a company – I don’t want to embarrass the company by saying their name, so I’ll just say their initials – IBM…

[laughter]

…saying that they want to use something I wrote. Because I put this on everything I write, now. They want to use something that I wrote in something that they wrote, and they were pretty sure they weren’t going to use it for evil, but they couldn’t say for sure about their customers. So could I give them a special license for that?

Of course. So I wrote back – this happened literally two weeks ago – “I give permission for IBM, its customers, partners, and minions, to use JSLint for evil.”
 

Tonza

Member
Trust me, you don't know what licensing woes are.
.....

Damn, that sounds crazy. I know my case is quite simple but still the whole licensing stuff is so convoluted. (And I have Information law as a minor.... I wonder why I ever took it)
 

Fury Sense

Member
Hey. I do a lot of JS stuff, but I haven't touched sockets/node yet - so I wish I could be of more help. However, one of my co-workers is a wiz at this stuff (and all stuff, it feels like) and suggested that

1. When I decide to learn sockets, sock.js is the better technology and
2. This was one of the links he told me to look at, I can't remember where the rest of them were - but one was a video. The link I gave you also assumes knowledge about backbone, so hopefully you have some experience with JS front end frameworks.

edit: from youtubing around, this video -seems- nice, and I think it talks about multiple socket libraries with node
http://www.youtube.com/watch?v=z7FcriiKY10
Hey, thanks a lot for asking your co-worker. I'll definitely give these a shot today.
 
I have a question for you ASP.NET programmers. This is my first time programming in ASP.NET. Well we're getting 2 weeks into the project, done with the UI, and realized we cannot access the controls we have dynamically added to the page via javascript. We don't want to go back and redesign the whole thing. We just need access to this data to save to a database and redirect on a button click. Any ideas? here is what the page looks like, and all of the + buttons dynamically create a clone/append to the table.

FawLs22.jpg
 
Currently not giving all of my elements a name, jsut an ID. If i add a name for them all, I would be able to access via formcollection?
Edit: All names need to be unique, or can i loop through them if i have duplicates?
 

Zoe

Member
Forms use the name to pass the value along. If you have several inputs with the same name, only the last one (I believe) in the form will get saved.
 
Thanks, so i'll be creating new names for each one. I'll see if i can get this section to work...the next section, it will be the same, but 3 levels deep instead of 2. This is accessible on an image click that calls a C# function? or only on form submit?
 
wasn't able to access them using Forms. Notice these are just HTML elements added via javascript. Before we download FormsCollection, you are sure we can access this via a C# function if we are not POSTing anything?
 

Zoe

Member
Are you using WebForms or MVC?

Is there a reason you're avoiding any kind of POST? How were you planning to access the data then?
 
We're using ASP.NET and C# to create this application. We started by using asp control tags, then got to the point where we needed to dynamically generate content. With the postback, it reloads our page, and since we have collapsible sections, it would reload with everything collapsed again. We figured it would be easier to do it with javascript. Now we are at the point where we are getting errors with any kind of POST, because the DOM doesn't match what ASP thinks it should be. We figured we could click a save button, call a function, which would parse the HTML objects, and save/update our database.

Are we set up for failure this way? We have a tight deadline and can't see us starting from scratch again, unless there is a much better way of doing this.
 

Chris R

Member
We just found out about these today. How would they work, surround each section in one?

Best method is to do that. You don't want to wrap the entire page in one big one.

Just setup the content and then assign the triggers. They work great, just make sure to set the update mode to Conditional and use Async triggers.
 

Onemic

Member
Can anyone tell me what's wrong with this function? Been debugging my program for over a day and I think this function may be the culprit as to why the compiler keeps crashing, but I have no idea why. When it's not called, the program runs fine, but when called I get a garbled mess in the output and the compiler triggers a breakpoint. I've tried allocating more memory to str, thinking it might be an issue with there not being enough, but even with 500 characters allocated(it should really only be 18), the same problems still occur.

The function is supposed to apply a style to a valid EAN depending on the character the user inputs.

Code:
void EAN::toStrWithStyle(char* str) const {
    if (isRegistered()) {
        if (choice == '-') {
            sprintf(str, "%s-%s-%s-%s-%c", prefix, area, publisher, title, ean[strlen(ean) - 1]);
        }
        else if (choice == ' ') {
            sprintf(str, "%s %s %s %s %c", prefix, area, publisher, title, ean[strlen(ean) - 1]);
        }
        else  {
            toStr(str);
        }
    }
}
 
Best method is to do that. You don't want to wrap the entire page in one big one.

Just setup the content and then assign the triggers. They work great, just make sure to set the update mode to Conditional and use Async triggers.
Awesome, I'll play around with that. Our current method would have us just using the form to grab everything generated with JS. Using asp seems like a more sound solution tho
 
hey guys i'm doing this really basic computing assignment right now, so it's kind of embarrassing asking this in here but oh well. it's using the program JES (jython..hahaha) and i have to make the colors increase in red intensity from left to right.

when i execute it i just get the desired result in the first row. all other rows are pure red (255). when i put the 'r=r+1' in the first for loop it gives me the desired result VERTICALLY. but i want this to happen horizontally hence the reason why i put this in the second for loop. yet it's not working.



Code:
def firststripe(pic):
  width=256
  height=getHeight(pic)
  r=0
  for y in range(0,int(height*0.4)):
    for x in range (0,width):
      pixel=getPixel(pic,x,y)
      setColor(pixel,makeColor(r,0,0))
      r=r+1
 

Water

Member
when i execute it i just get the desired result in the first row. all other rows are pure red (255). when i put the 'r=r+1' in the first for loop it gives me the desired result VERTICALLY. but i want this to happen horizontally hence the reason why i put this in the second for loop. yet it's not working.
Think about when exactly you should set r = 0.
 
nv/m figured it out. i actually got rid of the r counter and used the x one in the for loop

so i ended up with setColor(pixel,makeColor(x,0,0))

thanks though.
 
Can anyone tell me what's wrong with this function? Been debugging my program for over a day and I think this function may be the culprit as to why the compiler keeps crashing, but I have no idea why. When it's not called, the program runs fine, but when called I get a garbled mess in the output and the compiler triggers a breakpoint. I've tried allocating more memory to str, thinking it might be an issue with there not being enough, but even with 500 characters allocated(it should really only be 18), the same problems still occur.

The function is supposed to apply a style to a valid EAN depending on the character the user inputs.

Code:
void EAN::toStrWithStyle(char* str) const {
    if (isRegistered()) {
        if (choice == '-') {
            sprintf(str, "%s-%s-%s-%s-%c", prefix, area, publisher, title, ean[strlen(ean) - 1]);
        }
        else if (choice == ' ') {
            sprintf(str, "%s %s %s %s %c", prefix, area, publisher, title, ean[strlen(ean) - 1]);
        }
        else  {
            toStr(str);
        }
    }
}

i'm assuming that prefix/area/etc. are c-style strings. have you tried checking that they are terminated correctly? it's possible they aren't, in which case the sprintf will continue adding whatever data follows the string (which could be any of your program data, for instance) until it does hit a null terminator, or an access violation (some other program's memory).

eg the following code:

Code:
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

#define LEN 8

struct StrStruct {
	char a[LEN];
	char b[LEN];
} mStruct;

int main()
{
	char str[LEN] = "1234567";
	char str2[LEN] = "hello";
	
	char out[255];
	
	strcpy(mStruct.a, str);
	strcpy(mStruct.b, str2);

	// Remove the terminator by changing it to another char.
	mStruct.a[LEN - 1] = 'a';

	sprintf(out, "%s", mStruct.a);
	cout << out << endl;
}

will output:

Code:
1234567ahello
 

NotBacon

Member
How can one validate input in C?

Trying to validating ints, doubles to make sure they're actually numbers and strings(using char arrays) being actual letters up to a certain length.

Use fgets() and sscanf()

Code:
int a; char b; char *c;
char buffer[100];
fgets(buffer, 100, stdin);
int result = sscanf(buffer, "%i %c %s", a, b, c);

sscanf() returns how many values it read successfully. So if I enter '23 G apple' on the command line sscanf() will return 3, whereas '23 24 apple' will make sscanf() return 2.
Best part is you can sscanf() the buffer as many times as you want after the fgets()
 

moka

Member
Guys, I have a question. I'm currently building a program that would allow me to search for 'products' using a variety of parameters (manufacturer, type, minimum price and maximum price). The problem I'm having is that any number of these parameters can be filled out by the user so that means I have to build a new SQL query for every scenario e.g. if a maximum price is only entered or only a manufacturer has been selected. The 'option' parameter for the switch is inputted to the method when it is called. Obviously, there are loads of if/else statements used to select the correct parameter. It just seems really ugly to me.

Here is currently how I'm doing it but I can't help but think there's a more elegant solution out there. Thanks.

Code:
StringBuilder query = new StringBuilder("SELECT * "
                                              + "FROM products "
                                              + "WHERE ");
        
        switch(option) {
            case 1:
                query.append("price <= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setDouble(1, roundDouble(productPriceMax));
                break;
            case 2:
                query.append("price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setDouble(1, roundDouble(productPriceMin));
                break;
            case 3:
                query.append("product_type = ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, productType);
                break;
            case 4:
                query.append("manufacturer = ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                break;
            case 5:
                query.append("manufacturer = ? AND price <= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setDouble(2, roundDouble(productPriceMax));
                break;
            case 6:
                query.append("manufacturer = ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setDouble(2, roundDouble(productPriceMin));
                break;
            case 7:
                query.append("manufacturer = ? AND product_type = ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setString(2, productType);
                break;
            case 8:
                query.append("product_type = ? AND price <= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, productType);
                statement.setDouble(2, roundDouble(productPriceMax));
                break;
            case 9:
                query.append("product_type = ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, productType);
                statement.setDouble(2, roundDouble(productPriceMin));
                break;
            case 10:
                query.append("price <= ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setDouble(1, roundDouble(productPriceMax));
                statement.setDouble(2, roundDouble(productPriceMin));
                break;
            case 11:
                query.append("manufacturer = ? AND price <= ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setDouble(2, roundDouble(productPriceMax));
                statement.setDouble(3, roundDouble(productPriceMin));
                break;
            case 12:
                query.append("product_type = ? AND price <= ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, productType);
                statement.setDouble(2, roundDouble(productPriceMax));
                statement.setDouble(3, roundDouble(productPriceMin));
                break;
            case 13:
                query.append("manufacturer = ? AND product_type = ? AND price >= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setString(2, productType);
                statement.setDouble(3, roundDouble(productPriceMin));
                break;
            case 14:
                query.append("manufacturer = ? AND product_type = ? AND price <= ?");
                statement = db.getConnection().prepareStatement(query.toString());
                statement.setString(1, manufacturer);
                statement.setString(2, productType);
                statement.setDouble(3, roundDouble(productPriceMax));
                break;
            default:
                throw new Exception("Please fill in at least one of the fields.");
        }
 

Kalnos

Banned
I have no idea if this is an option for you but I would just use LINQ (and the Entity Framework. :p)

The only alternative to your method that I know is doing the checks in the query itself, which is still ugly.
 

Big Chungus

Member
This is going to be along shot but I have a question about Link Buttons in ASP.NET

I'm creating a Data Grid View using LINQ to SQL, i'm pulling a first name, last name, telephone number and country from a table and i want to be able to edit the row by clicking on the first name.

I've tried a bunch of things but I just can't get it to work.

Anyone have any ideas?
 

hateradio

The Most Dangerous Yes Man
If an item is editable, doesn't the GridView add an "Edit" link to the side? In that case you would just add a double-click event on the first name's TD (or whatever element encompasses it) and trigger the edit event.
 

Chris R

Member
Guys, I have a question. I'm currently building a program that would allow me to search for 'products' using a variety of parameters (manufacturer, type, minimum price and maximum price). The problem I'm having is that any number of these parameters can be filled out by the user so that means I have to build a new SQL query for every scenario e.g. if a maximum price is only entered or only a manufacturer has been selected. The 'option' parameter for the switch is inputted to the method when it is called. Obviously, there are loads of if/else statements used to select the correct parameter. It just seems really ugly to me.

Here is currently how I'm doing it but I can't help but think there's a more elegant solution out there. Thanks.

If you are set on using SQL check the SqlParameter class. I'd keep some kind of list of SqlParameters and then join them into the SQL query at the end.

Then if you add a new part to the form (search by year released or something) you would only need to deal with it at the parameter level, the query joining stuff would all still work exactly the same.

SqlParameter also has the nice ability to prevent SQL Injection attacks if this is going to be a program people other than you might be using.

This is going to be along shot but I have a question about Link Buttons in ASP.NET

I'm creating a Data Grid View using LINQ to SQL, i'm pulling a first name, last name, telephone number and country from a table and i want to be able to edit the row by clicking on the first name.

I've tried a bunch of things but I just can't get it to work.

Anyone have any ideas?

Is whatever edit event being triggered? I don't work with DGVs but there should be some event associated with editing that should fire if you have everything wired up right. If that isn't firing you know something is wrong before you even get to edit stuff.

No VS on my macbook otherwise I'd fire up a simple new page and see if I couldn't get something working. If you still have issues I can work on something tomorrow!
 

Ether_Snake

安安安安安安安安安安安安安安安
Reposting from the indie games thread.

If I wanted to learn 3D programming, what would be the good approach?

I'd like to start doing specific 3D development, individual projects, like realistic snow (like in that Disney snow video), real-time GI, PBR materials, etc. It's complex stuff but of course I'd start with the basics.
 

Water

Member
Reposting from the indie games thread.

If I wanted to learn 3D programming, what would be the good approach?

I'd like to start doing specific 3D development, individual projects, like realistic snow (like in that Disney snow video), real-time GI, PBR materials, etc. It's complex stuff but of course I'd start with the basics.
Do you have some general programming background? Languages?
 

Ether_Snake

安安安安安安安安安安安安安安安
Do you have some general programming background? Languages?

Nope! But I have good experience with PBR, GI, etc., due to my experience with 3D rendering on the non-coding side.
 
Back with another HW question...

Ok, so the assignment is to use a function to populate two different arrays with user input, use another function to find the intersection of the first two arrays, and then use a function to print the intersection array.

Here is what I have:
Code:
#include "stdafx.h"
#define MAX 5

/*function prototypes*/
void getArray (int ar[], int size);
void getIntersect(int ar1[], int ar2[], int ar3[], int size);
void printIntersect (int ar[], int size);



int _tmain(int argc, _TCHAR* argv[])
{
	int one[MAX];
	int two[MAX];
	int intersect[MAX];
			
	getArray(one, MAX);
	getArray(two, MAX);
	getIntersect(one, two, intersect, MAX);
	printIntersect(intersect, MAX);
	
	return 0;
}



void getArray (int ar[], int size)
{
	int i;

	printf( "Enter 10 numbers: \n" );
	for(i = 0;i < size;i++){
		scanf("%d", &ar[i]);
	}
	printf("\n");
	
}


void getIntersect(int ar1[], int ar2[], int ar3[], int size)
{
	for(int i = 0;i < size;i++){
		for(int j = 0;j < size;j++){
			if(ar1[i] == ar2[j]){
				ar3[i] = ar1[i];
			}
		}
	}
}



void printIntersect (int ar[], int size)
{
	int i;

	printf("The intersection is: \n");
	for(i = 0;i < size;i++){
		printf("%d\n",ar[i]);
	}
	printf("\n");
}
The problem is when the output is printed, it displays some wonky values.
dve0N5f.jpg

I know why it's doing this, but I don't know how to fix it to just print out the intersecting values. Help?
 

Kansoku

Member
dve0N5f.jpg

I know why it's doing this, but I don't know how to fix it to just print out the intersecting values. Help?

The problem is with the size of the array and the function to get the intersects.
You create the array3 with a size of 5. This array3 is going to house the intersects, but what if there's less than 5 intersects? If there's 2, the remaining 3 positions would be "empty" (I know that Java would put "null" there). The second problem is that in the function to get the intersects, you compare the first number (1) to all other numbers. But there isn't any intersects, so it remains empty. You use i for the place to put the int on the array3, but since there's no intersect on i=0, it's empty there, and it moves to another position. You would need a separate variable for that.

What you could do is, if you NEED to use arrays:
first count the intersects, then create the array3 with this number, instead of MAX. Then you will compare the numbers, but instead of using i for the position on the 3rd array, use a different variable, and "++" it after you put something in the array.
Or use a list.
 

Water

Member
Nope! But I have good experience with PBR, GI, etc., due to my experience with 3D rendering on the non-coding side.

I'm not sure. Serious graphics stuff like GI is so complicated, you'll have to have solid general programming skill. I always tell people to not start programming with C++, but for this specific kind of thing it might make sense. It's one of the hardest languages in common use, but its syntax allows matrix/vector math to be written clearly, and that's a huge advantage specifically when doing/learning graphics. And it's also what a lot of the industry and researchers use.

If you had some pre-existing C++ skill, I'd be happy to point you to this awesome book that covers theory quite well while also teaching raw OpenGL basics. But starting from zero programming experience and trying to mess with that code might be painful. You could start reading it anyway and skip over the code details to get a hang of the theory, vector/matrix math, transformations etc. you have to understand to do graphics.

For jumping into actually rendering things with a minimum of fuss, check out OpenFrameworks:
http://openframeworks.cc/

One option would be to start from the Unity game engine and its C# scripting. Its environment is a bit of a mess at first before you get used to it, but it would also give you easy immediate access to doing 3D math and seeing results in real time, and also allows you write shaders (albeit in Unity's own way). Some advanced rendering is locked behind a high paywall, and in general it will get less and less of a reasonable environment the more you try to do yourself.

For interactive and visual programming there's Processing, a Java-based visual programming framework, but it's unfortunately short on 3D facilities, e.g. primitives for matrices, and Java's syntax would be painful for that anyway.

edit: Slavik81's suggestion reminds me that Udacity offers a choose-your-own-pace, no cost computer graphics course that is likely more motivating than following a book alone. It uses three.js, seems reasonable. Looking at the curriculum, I'd expect the course to be reasonably easy; it covers maybe 1/3 of the topics that my university's intro to graphics course does in one semester.
 

Slavik81

Member
Reposting from the indie games thread.

If I wanted to learn 3D programming, what would be the good approach?

I'd like to start doing specific 3D development, individual projects, like realistic snow (like in that Disney snow video), real-time GI, PBR materials, etc. It's complex stuff but of course I'd start with the basics.
I enrolled in Intro to Computer Graphics at my local university. YMMV, but it worked for me.

Nope! But I have good experience with PBR, GI, etc., due to my experience with 3D rendering on the non-coding side.
Oh... That will make it much harder. Graphics work requires solid programming skills and a lot of math. Still, artistic talent and familiarity with 3D concepts and tools is a significant benefit.
 

iapetus

Scary Euro Man
designing a good UI is such a pain in the ass. Also not a fan of how android ui stuff is handled, at least compared to ios.

More details? What do you dislike about the android UI stuff? I'll agree wholeheartedly with the first part - that's why it's so refreshing to work with a good UI designer. :D
 
More details? What do you dislike about the android UI stuff? I'll agree wholeheartedly with the first part - that's why it's so refreshing to work with a good UI designer. :D

I dunno. I feel like I'm going in circles with all the damn xml files and referencing this id and that id and this string and that string all potentially in different files (especially with strings!). And then somehow early on my R class got completely removed from the project when I was fucking about with the ui somehow and I literally cannot figure out still why that happened.

It might be because ui is second to getting this database stuff working (c.r.u.d) and kind of throwing things together to make sure it's doing what it should be. Or I just need to take a break from the project itself.
 
Edit: Sorted. Ignore the below, I'm an idiot! I hadn't declared my method in the. cpp correctly.

I have a C++ issue that I can't resolve. I'm trying to return a vector of vectors from a method.

The other methods that return vectors are as such...
Code:
std::vector<string> whatever = method(param);
Which allocate the returned vector fine.

However, when I try the following...
Code:
std::vector<std::vector<string>> whatever = method(param);
I get LNK1120 and LNK2019 errors.

Any ideas? I'm fairly new to C++ so it's entirely possible I'm missing something obvious.

Edit: actually, it seems that simply typing the method call throws the same errors without trying to allocate to another vector of vectors.
 

Kalnos

Banned
José Mourinho;105527705 said:
However, when I try the following...
Code:
std::vector<std::vector<string> whatever = method(param);
I get LNK1120 and LNK2019 errors.

I haven't used C++ in forever but don't you need a closing '>' on that before 'whatever'?
 
How long did it take most of you to understand Java? I'm taking a beginner's course, but it's still not clicking to me. I'm having a hard time doing assignments that consist of either constructors or loops.
 
How long did it take most of you to understand Java? I'm taking a beginner's course, but my Professor doesn't really give many examples. The Udacity videos that were linked earlier aren't helping either.

It really depends on what you mean by 'understand'. I feel like I have a fairly good grasp on the language, but I know there are definitely other programmers who would make me look like a complete dunce.
 

Chris R

Member
How long did it take most of you to understand Java? I'm taking a beginner's course, but it's still not clicking to me. I'm having a hard time doing assignments that consist of either constructors or loops.

I only really "got it" about halfway through my first semester. If you have questions feel free to ask them though. I haven't touched Java in years but others know it well and basic programming questions don't vary much from language to language.
 
Are there any videos that help you understand the language more? I'd love to understand why we use these methods. I think the problem with my class is the Professor not really explaining why we use certain methods to solve an assignment.
 
Are there any videos that help you understand the language more? I'd love to understand why we use these methods. I think the problem with my class is the Professor not really explaining why we use certain methods to solve an assignment.

Methods as in techniques or literally the methods typed in the code?
 

hateradio

The Most Dangerous Yes Man
Are there any videos that help you understand the language more? I'd love to understand why we use these methods. I think the problem with my class is the Professor not really explaining why we use certain methods to solve an assignment.
Read the documentation. It may not be clear sometimes, but other times classes and their methods are explained well. However, that may not be the answer you want. :p

How long did it take most of you to understand Java? I'm taking a beginner's course, but it's still not clicking to me. I'm having a hard time doing assignments that consist of either constructors or loops.
Is Java the first language you're learning? Constructors are part of a Object Oriented Programming, and loops are . . . well they're general programing constructions to iterate over a collection or range of numbers.

You should probably read Head First Java. It explains things in some-what basic terms.
 

harSon

Banned
Need some more C++ help.

I'm trying to make a program that takes in a user input, passes it into an array, counts the frequency of a given vowel within the string and then outputs that amount:

Code:
#include <iostream>
#include <string>

using namespace std;

int countVowels(int [], char []);

int main()
{
  char str[257];
  int vowelCnt[5];
  cout << "Enter a character string (max 256): ";
  cin.getline (str,257);
  countVowels(vowelCnt, str);
  cout << vowelCnt[0] << endl;
  cout << vowelCnt[1] << endl;
  cout << vowelCnt[2] << endl;
  cout << vowelCnt[3] << endl;
  cout << vowelCnt[4] << endl;

}

int countVowels(int counts[], char str[])
{
    int vowelCnt[5] = {0};

    for (int i = 0; i < 257; i++) {

        if (str[i] == 'a' || str[i] == 'A') {
            vowelCnt[0]++;
        }
        else if (str[i] == 'e' || str[i] == 'E') {
            vowelCnt[1]++;
        }
        else if (str[i] == 'i' || str[i] == 'I') {
            vowelCnt[2]++;
        }
        else if (str[i] == 'o' || str[i] == 'O') {
            vowelCnt[3]++;
        }
        else if (str[i] == 'u' || str[i] == 'U') {
            vowelCnt[4]++;
        }
    }
    return *vowelCnt;
}

Debugging shows that str is holding some pretty funky characters outside the user input, and vowelCnt is holding some pretty funky numbers.

Any ideas?
 
Top Bottom