The Flat Earth Society

Other Discussion Boards => Technology & Information => Topic started by: spoon on January 27, 2014, 12:28:40 AM

Title: C++
Post by: spoon on January 27, 2014, 12:28:40 AM
I am taking a C++ course this semester to become mastr haxor. I am completely new to it but I find it fairly exciting. So far, the only program we've had to write modeled Newton's simple equation:

f=ma

However, I feel like it will get more complicated very soon. Can I rely on my FES brethren for help when necessary? I've looked ahead to Friday's assignment; it is to write a complete program to calculate the area of a triangle using dimensions supplied by the user. Seems simple enough.

Also, I was wondering if any of you could write a code that can read my assignments and produce the code for them? That'd be great.

Title: Re: C++
Post by: xasop on January 27, 2014, 12:41:39 AM
I'm decent (though not an expert) with C, and I hate C++. I will be able to help with a subset of C++ code.
Title: Re: C++
Post by: Pete Svarrior on January 27, 2014, 12:46:00 AM
I also hate C++, but I'm reasonably good at other object-oriented languages, which should make me more than good enough to help a C++ beginner.
Title: Re: C++
Post by: spoon on January 27, 2014, 12:50:17 AM
I C... get it? C..

Sorry about that. Anyways, why the disdain towards C++? What language do the two of you prefer?
Title: Re: C++
Post by: Lord Dave on January 27, 2014, 12:57:32 AM
I'm a mix of Parsifal and pizaaplanet.  I know some C++ (enough for you) but I'm more of a VB man.

Of course in my experience the easiest way to write code is to break down what you want it to do then look up how to do each piece.  Then put each one into a subroutine or function.
Title: Re: C++
Post by: spoon on January 27, 2014, 01:40:23 AM
Is VB related to Visual Studio? We use visual studio in the class.
Title: Re: C++
Post by: Snupes on January 27, 2014, 01:57:13 AM
I've been thinking about learning C++ for programming stuff, since that's what someone recommended I learn. I look forward to seeing how it goes for you. :D
Title: Re: C++
Post by: Rushy on January 27, 2014, 02:01:34 AM
Real men code in Assembly.
Title: Re: C++
Post by: spoon on January 27, 2014, 02:07:42 AM
I code in binary.
Title: Re: C++
Post by: Rushy on January 27, 2014, 02:10:27 AM
I code in binary.

I draw the line of hyperbole at the impossible. No one codes in binary.
Title: Re: C++
Post by: xasop on January 27, 2014, 02:12:29 AM
I've been thinking about learning C++ for programming stuff, since that's what someone recommended I learn.

Don't. Just don't.

I code in binary.

I draw the line of hyperbole at the impossible. No one codes in binary.

Incorrect. All coders code in binary.
Title: Re: C++
Post by: Rushy on January 27, 2014, 02:14:43 AM
Incorrect. All coders code in binary.

Incorrect. When I write in English and translate it to Russian using Google, it doesn't mean I wrote Russian.
Title: Re: C++
Post by: xasop on January 27, 2014, 02:15:17 AM
Incorrect. All coders code in binary.

Incorrect.

Incorrect.

When I write in English and translate it to Russian using Google, it doesn't mean I wrote Russian.

Irrelevant.
Title: Re: C++
Post by: Rushy on January 27, 2014, 02:16:21 AM
Irrelevant.

This is your universal sign of "I lost the argument."
Title: Re: C++
Post by: spoon on January 27, 2014, 02:17:20 AM
Irrelevant.

This is your universal sign of "I lost the argument."

Incorrect.
Title: Re: C++
Post by: xasop on January 27, 2014, 02:21:38 AM
Irrelevant.

This is your universal sign of "I lost the argument."

I'd have to have an argument in order to lose it. The only retort you made to me pointing out your wrongness was irrelevant.
Title: Re: C++
Post by: Rushy on January 27, 2014, 02:41:43 AM
I'd have to have an argument in order to lose it. The only retort you made to me pointing out your wrongness was irrelevant.

If there wasn't an argument, why then did you admit defeat? You must have seen the coming storm.
Title: Re: C++
Post by: Snupes on January 27, 2014, 11:32:14 AM
I've been thinking about learning C++ for programming stuff, since that's what someone recommended I learn.

What would you recommend?
Title: Re: C++
Post by: xasop on January 27, 2014, 12:24:27 PM
What would you recommend?

Most things that aren't C++.

More specifically, it depends on what you want to learn about programming. If you want to learn about how computers work, C is a great starting point. If you just want to write program logic without caring about what the computer is doing under the hood, a scripting language (Perl, Ruby and Python are popular options, in decreasing order of my personal preference) is a good way to ease into that.
Title: Re: C++
Post by: Pete Svarrior on January 27, 2014, 01:39:49 PM
I would also recommend a scripting language as your first language. My first real programming language was Java, and while Parsifal is likely to shoot me for saying this, if you don't want to work with a scripting language, Java is very easy to pick up. If you want to work in Visual Studio, C# is near-identical to Java in syntax, and is also fairly newbie-friendly.

I would advise against C or C++ as one's first language, because in my opinion a beginner programmer should be guided by hand a bit, and oh God does C(++) not do that. On the other hand, if you start with C++ and survive its shittiness, there's pretty much nothing that can stop you after that.

C(++) will do exactly what you tell it to do, without questioning anything. If you tell it to read memory that it shouldn't be reading, it'll read it. If you tell it to write to it, it'll try writing to it (and probably crash in the process). It will let you accidentally overwrite a completely unrelated variable if you write to the nth position in an n-size array, and it won't tell you that you're doing it. None of those things are too bad to someone that already has programming experience, but I would seriously not want to deal with that as a starter.
Title: Re: C++
Post by: beardo on January 27, 2014, 01:40:42 PM
What's the difference between C and C++?
Title: Re: C++
Post by: xasop on January 27, 2014, 01:57:48 PM
What's the difference between C and C++?

C++ is a poor imitation of OOP hacked on top of C.
Title: Re: C++
Post by: Lord Dave on January 27, 2014, 02:28:41 PM
What's the difference between C and C++?

C++ is a poor imitation of OOP hacked on top of C.

Basically this.
But for more specifics, C++ allows for objects.  What's an object?  Its a collection of variables and data that describe something.  For example: the post button is an object.  It has an image, width, height, alt text, and functions like mouse over (when you hover your mouse over it) and click.  All these bits are different types of data used to create one thing.



I recommend VB(Visual studio has Visual Basic in it) because its an object oriented language, its as easy as a scripting language, and it's forgiving. 
Its a good starter to understand basic logic and coding.  But you can't do much in the way of fancy things nor is it efficient in its compiled code.
Title: Re: C++
Post by: spoon on January 30, 2014, 12:20:38 AM
Well, I have run into my first roadblcok. I am getting this error message when I try to build:

error C4430: missing type specifier - int assumed.

It doesn't highlight any errors in my code, but it directs me to the line where I have my first squiggle bracket. Prior to the bracket I add the directives I need to and name the program (not sure if this is the correct language). I add the bracket then I start my code on the next line. Why is it directing me to this line? Based on the error, it seems as if I didn't specify my variable types. However, I declared every variable as "double". I had six variables and two constants, which I also declared as double. I am not too sure where I made my mistake. Would I need to post the code or does anybody have an idea where I am at fault?
Title: Re: C++
Post by: Lord Dave on January 30, 2014, 01:08:00 AM
Post the code.
Title: Re: C++
Post by: spoon on January 30, 2014, 01:17:59 AM
#include <iostream>
#include <cmath>

using namespace std;

main()
{
   double Angle;
   double IVelocity;
   double HorVelocity;
   double VertVelocity;
   double Time;
   double HorDist;
   const double PI = 3.14159265;
   const double Accel = 9.8;

   cout << "The object's initial flight angle above horizontal is ";
      
      cin >> Angle;

   cout << "The initial velocity of the object is ";
   
      cin >> IVelocity;
   
   VertVelocity = IVelocity * sin(Angle * PI / 180);
   HorVelocity = IVelocity * cos(Angle * PI / 180);
   Time = VertVelocity / Accel;
   
   HorDist= HorVelocity * Time;

   cout << "The horizontal distance travelled by the object is " << HorDist;

system( "pause" );
return 0;

}

I realize this might not be organized well. Remember, i m nub.
Title: Re: C++
Post by: spoon on January 30, 2014, 01:19:00 AM
btw, we are modelling projectile motion, if that isn't clear.

Also, this is my first guess at how to do this. I could be completely wrong.
Title: Re: C++
Post by: Lord Dave on January 30, 2014, 01:58:28 AM
I'm out of the loop on C++ but ... Pretty sure you need "int main()" if you're going to return an integer.

In fact, take out the 0 in the return and see if that fixes it.
Title: Re: C++
Post by: spoon on January 30, 2014, 02:01:18 AM
I'm an idiot. "int main()" fixed it. Thanks haha

Title: Re: C++
Post by: beardo on January 30, 2014, 05:25:49 AM
#include <iostream>
#include <cmath>

using namespace std;

main()
{
   double Angle;
   double IVelocity;
   double HorVelocity;
   double VertVelocity;
   double Time;
   double HorDist;
   const double PI = 3.14159265;
   const double Accel = 9.8;

   cout << "The object's initial flight angle above horizontal is ";
      
      cin >> Angle;

   cout << "The initial velocity of the object is ";
   
      cin >> IVelocity;
   
   VertVelocity = IVelocity * sin(Angle * PI / 180);
   HorVelocity = IVelocity * cos(Angle * PI / 180);
   Time = VertVelocity / Accel;
   
   HorDist= HorVelocity * Time;

   cout << "The horizontal distance travelled by the object is " << HorDist;

system( "pause" );
return 0;

}

I realize this might not be organized well. Remember, i m nub.
Gibberish.
Title: Re: C++
Post by: xasop on January 30, 2014, 06:01:58 AM
Thanks for posting that and reminding me why I hate C++.
Title: Re: C++
Post by: beardo on January 30, 2014, 06:27:42 AM
What would the equivalent code in C look like?
Title: Re: C++
Post by: xasop on January 30, 2014, 06:33:13 AM
What would the equivalent code in C look like?

I'll translate it when I get home. It's mostly similar, except that C doesn't pretend to be OOP.
Title: Re: C++
Post by: Pete Svarrior on January 30, 2014, 08:18:42 AM
I'll translate it when I get home. It's mostly similar, except that C doesn't pretend to be OOP.
Given that the code posted doesn't even attempt to use objects*, I struggle to think what you're on about.

I'm out of the loop on C++ but ... Pretty sure you need "int main()" if you're going to return an integer.

In fact, take out the 0 in the return and see if that fixes it.
In C++, main() has to be defined as returning an int. Also, if you wanted to define a function that returns nothing, just saying stuff() would be incorrect. What you'd need is void stuff(). Also, you should never advise people for their C(++) programs to do anything else than return 0 (or EXIT_SUCCESS, which is technically better) at the end of their successfully-executed programs.

What would the equivalent code in C look like?
It would use printf() (http://www.cplusplus.com/reference/cstdio/printf/) or puts() (http://www.cplusplus.com/reference/cstdio/puts/) instead of cout, and scanf() (http://www.cplusplus.com/reference/cstdio/scanf/) or gets() (http://www.cplusplus.com/reference/cstdio/gets/) instead of cin. The code would flow pretty much the same, and Parsifal is just being a massive gays.

* - inb4 Parsifal points out that cin and cout are technically objects.
Title: Re: C++
Post by: Lord Dave on January 30, 2014, 10:45:08 AM
I'm out of the loop on C++ but ... Pretty sure you need "int main()" if you're going to return an integer.

In fact, take out the 0 in the return and see if that fixes it.
In C++, main() has to be defined as returning an int. Also, if you wanted to define a function that returns nothing, just saying stuff() would be incorrect. What you'd need is void stuff(). Also, you should never advise people for their C(++) programs to do anything else than return 0 (or EXIT_SUCCESS, which is technically better) at the end of their successfully-executed programs.

Ah yes. Thank you.
Title: Re: C++
Post by: spoon on June 04, 2014, 05:46:27 PM
I downloaded a library called PNGwriter (http://pngwriter.sourceforge.net/). I would like to use it, but I am clueless as to how I would go about doing that in visual studio.

I know that I would need to #include the library, but I don't really know how to do that. Any insight would be appreciated.
Title: Re: C++
Post by: spoon on June 04, 2014, 05:49:26 PM
Further research tells me it's not exactly easy to do on windows. ugh

Basically, what I want to do is take the output from my code and format it on a png file. halp.
Title: Re: C++
Post by: Pete Svarrior on June 04, 2014, 06:17:58 PM
Basically, what I want to do is take the output from my code and format it on a png file. halp.
It seems like you already found a library that does that. Now you just need to stop whining that computers are hard and start actually using it.

As for figuring out how to link libraries in Visual Studio - I haven't worked with VS in ages, so I can't really guide you, but I just gave you all the keywords you need for your Google search to work.
Title: Re: C++
Post by: fappenhosen on June 04, 2014, 06:28:59 PM
Well, I have run into my first roadblcok. I am getting this error message when I try to build:

error C4430: missing type specifier - int assumed.

This is telling you that you are missing a type a type identifier.
Title: Re: C++
Post by: spoon on June 04, 2014, 07:27:06 PM
Basically, what I want to do is take the output from my code and format it on a png file. halp.
It seems like you already found a library that does that. Now you just need to stop whining that computers are hard and start actually using it.

As for figuring out how to link libraries in Visual Studio - I haven't worked with VS in ages, so I can't really guide you, but I just gave you all the keywords you need for your Google search to work.

nah it's too hard

I just converted it to a word doc lol
Title: Re: C++
Post by: Pete Svarrior on June 04, 2014, 08:21:52 PM
Why are you writing C++ with that kind of attitude?
Title: Re: C++
Post by: Lord Dave on June 04, 2014, 09:03:21 PM
Further research tells me it's not exactly easy to do on windows. ugh

Basically, what I want to do is take the output from my code and format it on a png file. halp.

http://pngwriter.sourceforge.net/howto_msvc.php
This seems pretty simple.
Title: Re: C++
Post by: spoon on June 04, 2014, 11:45:46 PM
Further research tells me it's not exactly easy to do on windows. ugh

Basically, what I want to do is take the output from my code and format it on a png file. halp.

http://pngwriter.sourceforge.net/howto_msvc.php
This seems pretty simple.

That's what I was using as a reference, but I was having trouble understanding some terminology. I don't know what "cascade" means, and google wasn't conclusive. Also, step 8 was unclear to me.  Change “Active Solution Configuration” to “LIB”. "LIB" was not an option. Rather, I had four variations of LIB. I don't know how to "clean" my solution.

I am assuming that the unclear directions are present because the instructions were written for an older version for VS.

I found an easier way, albeit less effective, to acheive my goal.

Why are you writing C++ with that kind of attitude?

I'm new at this  :(
Title: Re: C++
Post by: Fortuna on June 10, 2014, 08:25:59 AM
You should just learn Java. It's easier and you can make a decent career out of it.