Any chance you switched the numerator and denominator?
Hmm, I was trying to avoid having crazy amounts of code up. This is my best attempt to shorten it into what's happening:
Linked list function that adds nodes to the tail (**info is actually that last node's next pointer)
Code:void listValues( char *integer, struct values **info ) { struct values* current = (struct values*)malloc(sizeof(struct values)); current->num = atoi(integer); current->next = *info; *info = current; }
In another function, a switch case performs the operation (addition in this case), stores it in the next to last node and cuts ties with the last node.
Again, using the example above I get 4 instead of 20.Code:case '+': first = first + second; replacement->num = first; replacement->next = '\0'; break;
Anyone with some Groovy/Grails experience here? I have a class project with some pretty strict guidelines to follow, specifically that I need to make a "Course" table in my database with a non-standard primary key. Instead of the default 'id: Integer' that is created automatically, I need a column called 'code' of type String.
Code:class Course { String title static constraints = { title blank: false } static mapping = { version false id column: 'code', type: 'string', generator: 'assigned' } }
This works fine, but then I can't save any objects I create:
Code:def foo = new Course(title: "bar") foo.save() [B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B] def foo = new Course(title: "bar", code: "baz") foo.save() [B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B] def foo = new Course(title: "bar", id: "baz") foo.save() [B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B]
I always get the same error, what am I doing wrong?
class Course {
[B]String id[/B]
String title
static constraints = {
title blank: false
}
static mapping = {
version false
id column: 'code', type: 'string', generator: 'assigned'
}
[B]void setCode(String code) {
id = code
}
String getCode() {
return id
}[/B]
}
Congrats! Is that for an undergraduate or graduate course?Finally found a fix!
it sounds like it's dividing 3 / 49 and then adding 4 to the 0 it pushes back.
Edit: oh hey, I guess I should read more.
Yeah, I don't think I can help without seeing more code. how are you getting the values out of your linked list? what are the definitions for all of your operations? show me that code.
struct values
{
int num;
struct values *next;
};
---------
struct values *infoHead = '\0';
struct values *infoTail;
struct values *infoCounter;
---------
// Add to memory, calculate or print
while( scanf( "%s", data ) != EOF )
{
if( ispunct( *data ) != 0 )
{
count = amountOfValues( infoHead );
computeValues( data, infoHead, &infoCounter, count );
infoTail = infoCounter;
infoCounter = infoHead;
continue;
}
else if( isdigit( *data ) != 0 )
{
listValues( data, &(infoTail->next) );
infoTail = infoTail->next;
}
else if( *data == 'P' || *data == 'p' )
{
printf( "Expression = %d\n", infoTail->num );
}
}
void listValues( char *integer, struct values **info )
{
struct values* current = (struct values*)malloc(sizeof(struct values));
current->num = atoi(integer);
current->next = *info;
*info = current;
}
void computeValues( char *operator, struct values *info, struct values **refInfo, int count )
{
int i;
int first;
int second;
struct values* current = (struct values*)malloc(sizeof(struct values));
struct values* replacement = (struct values*)malloc(sizeof(struct values));
current = *refInfo;
replacement = info;
// Get values from nodes and check for enough values
for( i = 1; i < count - 1; i++ )
{
replacement = replacement->next;
}
first = replacement->num;
if( replacement->next == '\0' )
{
printf( "Error: Not enough operands. Quitting program.\n" );
exit(1);
}
else
{
replacement = replacement->next;
second = replacement->num;
}
for( i = 1; i < count - 1; i++ )
{
current = current->next;
}
//Compute expression
switch( *operator )
{
case '+':
first = first + second;
current->num = first;
current->next = '\0';
break;
Meeehhhh vector.erase() ruins everything by copying into a new resized container.
My needs for it make it run in O(n^2) instead of O. Meehhhh. No go.
edit: woot. iter_swap and pop_back() fixed that, now it runs closer to O(1);
EDIT: Though, if you're just talking about a single element, then nevermind.
$().ready(function () {
$('.account_type').change(function() {
var acctype = $('select.account_type').val();
if(acctype=='project' || acctype == 'default') {
$('.entrygroup_sql').fadeOut();
}
if (acctype=='project_mysql' || acctype == 'mysql_only') {
$('.entrygroup_sql').fadeIn();
}
});
// validate the comment form when it is submitted
$("#commentForm").validate();
// validate signup form on keyup and submit
$("#signupForm").validate({
rules: {
account_type: "required",
first_name: {
required: true,
lettersonly: true,
minlength: 2
},
last_name: {
required: true,
lettersonly: true,
minlength: 2
},
email_address: {
required: true,
email: true
},
phone_number: {
required: true,
digits: true,
minlength: 2
},
account_name: {
required: true,
alphanumeric: true,
minlength: 2
},
project_name: {
required: true,
lettersonly: true,
minlength: 2
},
disk_quota: {
required: true,
digits: true,
min: 1
},
major: "required",
project_advisor: {
required: true,
lettersonly: true,
minlength: 2
},
advisor_email: {
required: true,
email: true,
minlength: 2
},
unix_shell: {
required: true
},
num_participants: {
required: true,
digits: true,
min: 1
},
database_location: {
required: true
},
messages: {
account_type: "Please select an account type",
first_name: {
required: "First name is required",
lettersonly: "Letters only",
minlength: "Your username must consist of at least 2 characters"
},
last_name: {
required: "Last name is required",
lettersonly: "Letters only",
minlength: "Your username must consist of at least 2 characters"
},
email_address: {
required: "An Email address is required",
email: "Please enter a email address"
},
phone_number: {
required: "Please enter a phone number",
digits: "Please enter digits only",
minlength: "Your username must consist of at least 10 digits with areacode"
},
account_name: {
required: "Account name is required",
alphanumeric: "Alphanumeric please",
minlength: "Your username must consist of at least 1 characters"
},
project_name: {
required: "Project name is required",
lettersonly: "Letters only",
minlength: "Your username must consist of at least 1 characters"
},
disk_quota: {
required: "Disk Quota is required",
digits: "Please enter digits only",
min: "Please enter a number"
},
major: {
required: "Major is required"
},
project_advisor: {
required: "Project advisor is required",
lettersonly: "Letters only",
minlength: "Your username must consist of at least 1 characters"
},
advisor_email: {
required: "Project advisor email is required",
email: "Please enter a email address",
minlength: "Your username must consist of at least 1 characters"
},
unix_shell: {
required: "Unix shell is required"
},
num_participants: {
required: "Number of participants is required",
digits: "Please enter digits only",
min: "Please enter at least one participant"
},
database_location: {
required: "Please enter a database location"
}
}
}
});
});
I guess in the attempt to not put more than I need I've really dragged this out haven't I? I'll not make that mistake again.
This is the juicy bit of main. It's been reduced a tad but all the important bits should be there now.
Thank you guys for being patient with me. I'm still learning!
It's not really long; the longest part are validation rules, think of it like JSON.^^ Long function is long. Would jquery allow you to break that up a bit? Might make it more obvious what's going wrong and where when you can see it in smaller, digestible, named chunks.
I've never used validate, but you should change the first part from $().ready(function... to jQuery(function.... It's a bit cleaner.Anyone with experience in Jquery? I'm working on my group project's front end and nothing comes out. Here's the basic syntax of the code. This is a competitive class so I won't ... post everything but here's the jist of it. Thanks!
Code:$().ready(function () { $('.account_type').change(function() { var acctype = $('select.account_type').val(); if(acctype=='project' || acctype == 'default') { $('.entrygroup_sql').fadeOut(); } if (acctype=='project_mysql' || acctype == 'mysql_only') { $('.entrygroup_sql').fadeIn(); } }); // validate the comment form when it is submitted $("#commentForm").validate(); // validate signup form on keyup and submit $("#signupForm").validate({ . . . }); });
Anyone with experience in Jquery? I'm working on my group project's front end and nothing comes out. Here's the basic syntax of the code. This is a competitive class so I won't ... post everything but here's the jist of it. Thanks!
Java is radically simpler. The switch shouldn't be very hard at all. It's a lot easier than going the other way.just a few quick questions:
i have steadily gotten better at C++, and now I have to drop everything and switch to java. Is java that hard to transition to if I already understand the principles of OOP?
second, do you prefer C++ or java and why?
thanks
- Is your prof teaching you to use structs and malloc like that in C++?
- Your computeValues function is cut off. I don't see where it removes elements from the list.
- what does this function do? what is the significance of the integer it returns? amountOfValues( infoHead );
I assume this is supposed to be the head of the linked list. *infoHead = '\0';
and this is supposed to be the tail*infoTail;
what, then, is this supposed to be? *infoCounter;
- It seems like what you're trying to do is, when you read in an operator, you walk to the end of the list to grab the last 2 elements, operate on them and store the result in the first of the two then discard the second at the tail.
- when you walk the list in those for loops it's kind of awkward to run from one to less than count - 1. you wind up looping count - 2 times. it's a lot more readable if you just return a count that's 2 smaller and run i = 0 to i < count. That is of course if you intend for a count of 5 to walk you forward 3 nodes in the list.
- are you forbidden from adding list elements more like a stack? in front of each-other instead of behind?
int amountOfValues( struct values* head )
{
int count = 0;
struct values* counter = head;
while( counter != '\0' )
{
count++;
counter = counter->next;
}
return count;
}
Java is radically simpler. The switch shouldn't be very hard at all. It's a lot easier than going the other way.
I think java and c++ both have their uses. If I was going to solve something I could do in a single sitting, I'd prefer to use java by about 100x. You can get things done much more quickly. There are many languages I'd choose over java though.
If I was writing a game, or a general purpose library, or a command line tool, I'd use C++. But there are languages I'd choose before c++ for those tasks, too.
But the biggest factor is familiarity.
Java for C and C++ Programmers
Java for C++ Programmers
Wikipedia: Comparison of Java and C++ (syntax)
Is java that hard to transition to if I already understand the principles of OOP?
second, do you prefer C++ or java and why?
thanks
So the re-education (sounds evil) of Randolph Freelander (sounds third person) is continuing merrily along.
I am now relearning Calculus, which is something I have wanted to do for years. It's interesting how dumb it's making me feel. It has been umpteen years since I did math of this nature, and man am I rusty (which is why I'm relearning).
It's amazing. The first lecture video I watched from MIT's 18.01 (Single Variable Calculus - Fall 2006 [actually filmed in 2007... don't ask]) made me feel stupid while it was showing me something I already knew. Namely, finding derivatives of polynomials, for example. Like, dude arrived at the formula which I still remembered, but the math for arriving at that formula highlighted just how much I have forgotten over the years.
Fortunately, I've been through a couple more lecture videos this evening, and it's knocking some of the rust off.
-Our class is winding down on C and moving on to C++. I'm currently writing it in C because I don't have a lot of time to be making syntax errors and I'm more comfortable with that.
-Crap. The rest of the function is just four more switch cases that do the exact same operation (subtraction, multiplication, division and modulus). By making the ->next pointer in the second to last node null aren't you removing the last node from the list itself?
-It just rides the list and finds out how many values there currently are.Code:int amountOfValues( struct values* head ) { int count = 0; struct values* counter = head; while( counter != '\0' ) { count++; counter = counter->next; } return count; }
-infoCounter would be the duct tape I used to try and get the program up and running. I was encountering a problem where I would put infoHead into the compute function and the head pointer would remain at the tail of the list even after I tried to have it point back to the head. I used another pointer to ride down the list instead so infoHead would never move.
-That's correct (what I'm doing in compute). Good to know, I'll make sure to design my for loops a little cleaner next time.
-There's nothing forbidding me from putting nodes on the head instead of the tail. This way just made more sense to me so I did it this way.
So the re-education (sounds evil) of Randolph Freelander (sounds third person) is continuing merrily along.
I am now relearning Calculus, which is something I have wanted to do for years. It's interesting how dumb it's making me feel. It has been umpteen years since I did math of this nature, and man am I rusty (which is why I'm relearning).
It's amazing. The first lecture video I watched from MIT's 18.01 (Single Variable Calculus - Fall 2006 [actually filmed in 2007... don't ask]) made me feel stupid while it was showing me something I already knew. Namely, finding derivatives of polynomials, for example. Like, dude arrived at the formula which I still remembered, but the math for arriving at that formula highlighted just how much I have forgotten over the years.
Fortunately, I've been through a couple more lecture videos this evening, and it's knocking some of the rust off.
Well, what is your IDE?
It's quite amazing how much more sense a lot of the things I "learned" in college make to me now. I reread through my old Data Structures book a few months ago in my quest to pull myself out of the sysadmin hole I've dug for myself in recent years and it's night and day.
Education is wasted on the young!
*Important linked list lesson*
Guess I should rewrite my program with this in mind then. Seriously, thank you for the help. When I can give back I will.
Just curious, in what context are you doing this assignment? I though postfix calculator is a classic stack application.
Just curious, in what context are you doing this assignment? I though postfix calculator is a classic stack application.
Our last assignment using linked lists, however, was a first in-first out scenario and I had added at the tail and removed from the head for that assignment. I figured since I already had an understanding of how that worked I would run with that and adjust accordingly for this assignment.
I've never used validate, but you should change the first part from $().ready(function... to jQuery(function.... It's a bit cleaner.
Nah, just do
Code:$(function() { //Your stuff here });
Also, I need help on doing alphanumeric, letters only validation. But progress. There's something at least.
I was a little bit baffled when I didn't see the pop and push operations in your code, I thought you are working on some other topic ( like lexical analysis or something).
or put the javascript file at the bottom of the HTML file and then you don't have to wait for the dom
regex maybe?
Hi folks and folkettes,
I'm in need of some guidance here. I've scoured the internet (read: Google search results) for help, and I think the minds of this thread may be able to aid me better.
I'm wanting to install and begin to learn how to use OpenGL (specifically, JOGL). Can someone please give me a "for dummies" step-by-step guide for how to get it up and running in my IDE of choice? It may be best to assume I'm entirely clueless and know just the basic terminology (some of these tutorials I've been looking at are a bit over my head with the terms). I'm starting to feel like a big idiot because I can't figure this out.
Really I'm just looking for help in getting it working in my IDE. Any help would be greatly appreciated. Thanks so much in advance to anyone who can help!
Is it recommended to use functions named "push" and "pop?" That's how our professor and material referred to them but I figured that was just used for instructional purposes.
Hi folks and folkettes,
I'm in need of some guidance here. I've scoured the internet (read: Google search results) for help, and I think the minds of this thread may be able to aid me better.
I'm wanting to install and begin to learn how to use OpenGL (specifically, JOGL). Can someone please give me a "for dummies" step-by-step guide for how to get it up and running in my IDE of choice? It may be best to assume I'm entirely clueless and know just the basic terminology (some of these tutorials I've been looking at are a bit over my head with the terms). I'm starting to feel like a big idiot because I can't figure this out.
Really I'm just looking for help in getting it working in my IDE. Any help would be greatly appreciated. Thanks so much in advance to anyone who can help!
Well, that's the convention when people think about stack problems. Also, stack is a fundamental hardware data structure and almost all CPUs have push/pop assembly instruction (that's why rhfb mentioned assembly class), it's only beneficial you have a good understanding of it. IMHO, you should have a nice implementation of a stack class based on your linked list, independent from your RPN calculator. Just FYI, C++ has the stack container class derived from vector, deque and list classes.
A char is actually just 1 byte, not 2.
I'll use something very close to this, thanks. I thought I needed something exactly 40 bits in size but I can obviously just move 5 bytes at a time from the pointer and ignore the rest.H1111111 1LH22222 222LH333 33333LH4 4444444L
=
((( ((((H x 256 + 11111111 ) x4+LH ) x 256 + 22222222 ) x4 + LH ) x 256 + 33333333 )x4 + LH ) x 256 + 44444444) x2+L)
A long integer should be able to hold all 40bits, and x256 can be replaced with <<8
Really? On all architectures? I might be getting my languages mixed up by assuming it's two. I totally remember doing x86 stack stuff by casting pointers to chars at some point in C so it obviously makes sense that chars are the same in C++.
Really? On all architectures? I might be getting my languages mixed up by assuming it's two. I totally remember doing x86 stack stuff by casting pointers to chars at some point in C so it obviously makes sense that chars are the same in C++.
A char is defined as 1 byte. Theoretically the number of bits in a byte can change depending on architecture (though that doesn't really happen these days). The CHAR_BIT macro will tell you that information.
Those casts you're talking about sound suspicious. The integer type for holding a pointer is uintptr_t. A char is almost certainly too small. Perhaps you mean you were casting from void* to char*?