Author Topic: Programming Megathread  (Read 143732 times)

I've been working on something for a while, it's a simple little websocket chat server and client, and it's also what I was looking at requirejs for, previously
both parts are written in javascript, with node as the server and the client is a web page (but hypothetically you could make different clients, as long as you can use websockets)
recently I've decided that I want to make a few big changes to it, that would require a lot of code changes. so I'm thinking about rewriting it in coffeescript. I'm pretty sure that would get rid of the need to use something like requirejs, while still allowing me to separate the client's source into several files (I think? I'm probably gonna have to take a closer look at how coffeescript works)
I guess I'll think about it. maybe. maybe I'll only do the client in coffeescript. I dunno, we'll see how it goes
I'm demoing this code to my college of people who want but cannot program, so I need to really intricately explain every little detail.
I think it makes it look a lot more confusing. like, if you've never touched a programming language, all those comments are definitely gonna make it look more complex
instead, I'd use a separate document where you explain what the code is doing
since you're using C#, I'd suggest Nocco. in this case, the comments are still in the source, but when you show it to them, they'll be to the side instead

if you've never touched a programming language, all those comments are definitely gonna make it look more complex
These guys have done a programming class with C# so they know what's up; it's the logic they're struggling with.

since you're using C#, I'd suggest Nocco. in this case, the comments are still in the source, but when you show it to them, they'll be to the side instead
Oh jeeze, that thing is beautiful. Thanks for the heads-up.

Oh jeeze, that thing is beautiful. Thanks for the heads-up.
it's based on Docco, which could do it for you just as well, but Docco requires node.js, and you may not want to install that and npm just to use it
it seems like some of the ports made in languages other than CoffeeScript only work with their respective language, for some reason. I'm sure it has something to do with syntax highlighting. but both JavaScript and Python have very wonderful syntax highlighting libraries, so I'd go with the original Docco or Pycco if you don't use Nocco

So I'm currently making a c++ program that determines if four side lengths inputted by the user could form a polygon, which I have done already. If they can form a polygon, the program has to determine if the sides form a rectangle or a square. The issue is that I'm not sure how to go about making an algorithm that checks if they form a rectangle(begins on the last line).

I have to do this assuming I only know how to use relational and logical operators and simple selection routines.

Here's what I have so far:
Code: [Select]
//Lab 8 - Problem 3

#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;

int main()
{

float a, b, c, d;

cout<<"This program will determine whether four side lengths could form a polygon. If they can, the program will also determine if the sides could form a rectangle or square.";
cout<<"side 1= ";
cin>>a;
cout<<"side 2= ";
cin>>b;
cout<<"side 3= ";
cin>>c;
cout<<"side 4= ";
cin>>d;

if (a<b+c+d&&b<a+c+d&&c<a+b+d&&d<a+b+c)
{cout<<"A polygon can be formed from these four side lengths.";
if ()

Any suggestions?

Check if both opposing sides are the same.

if(a == c && b == d) { cout << "It's a rectangle!"; }

Otherwise, it's a polygon.

Alternately,

if(a > b+c+d || b > a+c+d || c > a+b+d || d > a+b+c) {
  cout << "A polygon cannot be formed.";
} else if(a == c && b == d) {
  cout << "It's a rectangle!";
} else {
  cout << "It's a polygon!";
}


If it has to be any 4 sides, then it gets a little more complicated:

if((a == b && c == d) ||
   (a == c && b == d) ||
   (a == d && b == c)) {
  cout << "It's a rectangle!";
}
« Last Edit: March 31, 2016, 08:15:35 PM by $trinick »

Check if both opposing sides are the same.

if(a == c && b == d) { cout << "It's a rectangle!"; }

Otherwise, it's a polygon.
Yeah but what if, for example, a=2, b=2, c=4, and d=4? Your suggestion wouldn't work. The program has to be able to check any set of numbers in any order.

Edit: Just saw your edit. I'll try it out, thanks!

Yeah but what if, for example, a=2, b=2, c=4, and d=4? Your suggestion wouldn't work. The program has to be able to check any set of numbers in any order.

Edit: Just saw your edit. I'll try it out, thanks!

Idk why that post in particular was loving with me but I kept editing it to make it more clear.

I can only code in scratch and smilebasic

but I'm great at scratch


If you can do that in scratch, you should really look into using other programming languages. Like, damn.

If you can do that in scratch, you should really look into using other programming languages. Like, damn.

its hard to compile others and I dont know anything about command line

I would do it if it had a built in compiler and some code snippets (so I can understand some code)

heres a video of the renderer in action (I also play around with the code while running it, causing all the skewing since it goes out of sync)
I also sped it up by replacing the custom block with the pen shade block.
here it is
« Last Edit: March 31, 2016, 08:59:55 PM by HooperScooper »

i got lua today and i don't know how i was living without it

Ravencroft          


made a pretty cool program for my c++ exam today
Code: [Select]
//Exam 2 - Problem 23

#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;

int main()
{
//variables
float y, a, b, w, x, q, h, g;
int choice;

//menu
cout<<"This program will will calculate the value of y, w, or q for each variable's designated equation:"
<<"\n"<<"\n"
<<"Choice 1 calculates the value of y for the equation 'y=10+[(5a)/(3b)]-4b^2' when the user inputs values for a and b."
<<"\n"
<<"Choice 2 calculates the value of w for the equation 'w=6x^5-15' when the user inputs a value for x."
<<"\n"
<<"Choice 3 calculates the value of q for the equation 'q=(3/4)h-(7g/6)' when the user inputs values for h and g."
<<"\n"<<"\n"
<<"Please enter a choice number: ";

//menu selection
cin>>choice;
while(choice>3)
{
cout<<"That is an invalid selection. Please enter choice number 1-3: ";
cin>>choice;
}

//choice outputs
switch(choice)
{
case(1):
{
cout<<"You have selected choice 1."
<<"\n"<<"\n"
<<"Enter a value for a: ";
cin>>a;
cout<<"Enter a value for b: ";
cin>>b;
y=10+((5*a)/(3*b))-(4*pow(b,2));
cout<<"y="<<y<<" when a="<<a<<" and b="<<b<<" for the equation 'y=10+[(5a)/(3b)]-4b^2'.";
break;}

case(2):
{
cout<<"You have selected choice 2."
<<"\n"<<"\n"
<<"Enter a value for x: ";
cin>>x;
w=6*pow(x,5)-15;
cout<<"w="<<w<<" when x="<<x<<" for the equation 'w=6x^5-15'.";
break;}

case(3):
cout<<"You have selected choice 3."
<<"\n"<<"\n"
<<"Enter a value for h: ";
{cin>>h;
cout<<"Enter a value for g: ";
cin>>g;
q=(3/4)*h-(7*g/6);
cout<<"q="<<q<<" when h="<<h<<" and g="<<g<<" for the equation 'q=(3/4)h-(7g/6)'";}
break;}
}

//end of program


Not that it has a real impact on the control flow in the switch statement, but if a user enters 0 for example

while(choice>3)

will not catch it and the program will just end with no indication of what happened.

Not that it has a real impact on the control flow in the switch statement, but if a user enters 0 for example

while(choice>3)

will not catch it and the program will just end with no indication of what happened.
Yeah I noticed that after I submitted it. Luckily we haven't started any material on loops yet. I just wanted to see if I could implement one into the program successfully since we start lecture on loops next week.

Yeah I noticed that after I submitted it. Luckily we haven't started any material on loops yet. I just wanted to see if I could implement one into the program successfully since we start lecture on loops next week.
... you have a while loop in the program though