How can I improve my software design? via /r/learnprogramming


How can I improve my software design?

Hey everyone, second year CS major here. The thing I think I'm struggling with most is designing software, such as what architectural pattern to use (e.g. MVC, event-driven, etc.) as well as what duties to delegate to each class.

Does anyone have books, materials, or online courses they can recommend?

Submitted April 30, 2017 at 06:17PM by MrsEveryShot
via reddit http://ift.tt/2oYEBbU

[SQL] Update ‘THIS’ row in a trigger function via /r/learnprogramming


[SQL] Update ‘THIS’ row in a trigger function

I have a table that has a column by where if the value of that column changes to 'C' – then the value of different column (but the same row) on the same table should change to 0.

Here is my table

| numseats | status | --------------------- | 4 | R | | 3 | R | | 9 | R | | 4 | R | 

So when R changes to C – numseats in that row should change to 0.

Here is my trigger and function

CREATE OR REPLACE FUNCTION removeSeats() RETURNS trigger AS $$ begin IF pg_trigger_depth() <> 1 THEN RETURN NEW; END IF; UPDATE flightbooking set OLD.numseats = 0; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER removeseats AFTER UPDATE on flightbooking FOR EACH ROW WHEN (flightbooking.status = 'C') EXECUTE PROCEDURE removeSeats(); 

I get the following error

ERROR: invalid reference to FROM-clause entry for table "flightbooking" 

However even if I get past that bit and actually call the function then it will set all values in numseats to 0… Where I just want ''THIS''.numseats to 0. I tried using OLD.numseats but that threw an error saying OLD did not exist.

Any ideas?

Submitted April 30, 2017 at 06:34PM by PM_Me_Compliments
via reddit http://ift.tt/2oNaOXA

Mapping interconnected objects in a workspace directory via /r/learnprogramming


Mapping interconnected objects in a workspace directory

I inherited a workspace project with numerous .py files and little documentation. I am trying to peel back the onion to see how everything is interconnected and it's extremely slow. For one file, say constants.py, there are 10 constants. I search the entire workspace directory by the constant name and write down where it's referenced and what it's doing. Same for another .py with a bunch of functions.

Is there a way to automatically map all the objects in a workspace into a flowchart or other type of diagram?

Working on mac osx

Submitted April 30, 2017 at 06:37PM by Omniphiscent
via reddit http://ift.tt/2oYI1eC

[CS50 Mario, C] Can someone point me in the right direction with my code? via /r/learnprogramming


[CS50 Mario, C] Can someone point me in the right direction with my code?

Any help would be appreciated.

#include <stdio.h> #include <cs50.h> int get_pyramid_height(); int main(void) { for (int height = 1; height < get_pyramid_height(); height++) { for (int width = 0; width < height; width++) { printf("#"); } printf("\n"); } } //get height from user int get_pyramid_height() { int n; do { printf("Give me a number 1-23: "); n = get_int(); } while ( n > 0 && n <= 23 ); return n; } 

Submitted April 30, 2017 at 04:38PM by Boogleyboogers
via reddit http://ift.tt/2qmw0ks

What would be your suggested method to learning how how to to make a chatroom? via /r/learnprogramming


What would be your suggested method to learning how how to to make a chatroom?

I'm not finding any good resources on how this would work online. It's kinda weird that their no templates online I think, but I only have basic knowledge of programming, and I'm just kinda good with computers so I'm confused

Submitted April 30, 2017 at 04:44PM by MyBonerIsBig
via reddit http://ift.tt/2pkCFgd

Help sorting objects? Blackjack game via /r/learnprogramming


Help sorting objects? Blackjack game

Hi reddit!! I need some help with a multiplayer blackjack game

So far I've the basic functionality of the program. I'm working with the following classes: Player, Dealer, Deck, Hand, Card, Game, and Blackjack(main).

I'm having trouble finding out who wins the round. To do so, i need to sort or compare the different values of the players' hands. I access the value of their hands with game.player[i].hand.handValue();

handValue is just a funtion that tells you the value of a player's hand. It considers that the ace can be 1 or 11.

How would I do this? I was thinking about sorting or comparing each player object(including the dealer) and the one with the highest handValue that isn't over 21, wins. But there's also the possibility of a draw("push")…

Somebody told me I could use compareTo, but I'm not sure exactly how this works…

Submitted April 30, 2017 at 04:45PM by TimmX97
via reddit http://ift.tt/2qmyXRJ

[c++] War Game help via /r/learnprogramming


[c++] War Game help

My professor gave me a lab to do which is to make a version of the war game. He gave us already some code that we are not supposed to modify in order to make the game work. He said not to modify intmain(), showcards(), and getnums(). So the issue is everytime I run the program it only displays 0 as a card, and I feel like its the random number generator that is the issue, which I am not supposed to modify since it is in intMain and getNums.

Here is the code: http://ift.tt/2pkGkL1

Submitted April 30, 2017 at 04:53PM by Reavity
via reddit http://ift.tt/2pkwrNo