Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Arrays, Bools, While

Name: Anonymous 2007-05-10 20:23 ID:GLGxfot7

Please help.

I have a C++ programming exam in 8 hours and I have no idea what to do.

I need to understand functions, while loops, do whiles, bools, arrays. Especially arrays. Simple, basic shit. I need this to pass my course.

Name: Anonymous 2007-05-10 20:30 ID:Heaven

YOU SHALL NOT PASS

Name: Anonymous 2007-05-10 20:33 ID:JHXqJ+AD

>>1
arrays =
a list of data types
example
char array[10] = 10 * sizeof(char) bytes = 10 bytes in a row in memory
int array[10] = 10 * sizeof(int) bytes = 40 bytes in a row in memory in 32 bit procesors

Name: Anonymous 2007-05-10 20:58 ID:R+GkUsax

This looks like a HUEG reference (I just randomly looked for C++ in wikibooks)
http://en.wikibooks.org/wiki/C%2B%2B_Programming/TOC1

Try and look up your topics there. Go thru a few examples in the book. I have a feeling this may be a troll, but if it isn't, have good luck. You can't pass this type of exams overnight, though, and your earlier midterm probably wasn't too bad, if you are here on 4chan on this board

Name: Anonymous 2007-05-10 21:08 ID:JHXqJ+AD

>>1
a struct is an array too, int is an array of bytes too.
a bool is a byte (not a bit)

Name: Anonymous 2007-05-10 21:41 ID:cbs/ufdS

>>1
Functions :

I guess you know what functions are, I'll show you how to use them with some examples

#include <iostream>
using std::cout;
using std::endl;

int no_u()//int is the return type
{
return 3;
#if 0 //the following code will not be executed but it also works
int uhNo = 3;
return uhNo;
#endif
}

void foo()//void = no return value
{
cout<<"NO U"<<endl;
}

void lulz(int helloLol,long shitty_parameter)/*helloLol and shitty_parameter are parameters you decide of their value when you call the function(see main) you can have as many parameters as you want*/
{
cout<<helloLol<<" "<<shitty_parameter<<endl;
}

int fourchan(int HAHAHAOHWOW)
{
return HAHAHAOHWOW+1;
}

int main(int argc, char *argv[])
{
cout << no_u() << endl;
foo();
lulz(2,4);//helloLol = 2, shitty_parameter = 4
fourchan(7);
return 0;
}
Bools :
A bool can have 2 values : true(any value but 0) and false(0)
int fourchan = 2<3//fourchan = true
int fourchan = false//fourchan = false
int fourchan = 3==3//fourchan = true


if(fourchan)//if fourchan is true do_something will be executed
{
do_something();
}


if(!fourchan)//if fourchan is false do_something will be executed
{
do_something();
}

if(fourchan==6)//if fourchan = 6(fourchan==6 returns a boolean)


While loops :

int main(int argc,char *argv[])
{
fourchan = 3;
while(fourchan<10)//AS LONG AS fourchan<10
{
cout<<fourchan<<endl;
fourchan ++;
}

}


Arrays are like a "list" of datas

int myArray[3];//a 3 ints array is declared
there are 3 values(like if you had 3 different variables) in this array

myArray[0]
myArray[1]
myArray[2]

myArray[0] = 3;
myArray[1] = 4;
etc.


If you understand that code you will probably be ready for your exam :

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

#define ARRAY_SIZE 5

void drawValuesInArray(int *array)
{
int pos = 0;//variables in main and in functions are not the same
while(pos<ARRAY_SIZE)
{
cout<<array[pos]<<endl;
pos++;
}

}

int main(int argc,char *argv[])
{
int pos = 0;
int lolarray[ARRAY_SIZE];

while(pos<ARRAY_SIZE)
{
cin>>lolarray[pos];
pos++;
}
drawValuesInArray(lolarray);
cin.get();
return 0;
}

Name: Anonymous 2007-05-10 22:09 ID:cbs/ufdS

oops I wrote
int fourchan = 2<3//fourchan = true
int fourchan = false//fourchan = false
int fourchan = 3==3//fourchan = true

int fourchan works but you can also write bool fourchan. Btw, it takes 1 byte and not 1 bit in memory

Name: Anonymous 2007-05-10 22:17 ID:GLGxfot7

Thank you guys so damn much, I have a chance now! :D

Name: Anonymous 2007-05-10 22:30 ID:GLGxfot7

Nah, it's not a troll. I barely got passed the mid-term, 5 marks over the failing point which was OK. Sort of.

I thought I'd be alright with what I knew, and had learned since, but after looking over the passed exam papers I realised that I was pretty damn fucked.
While I won't be able to but a lot of what I've just been told to immediate use, I'm a little bit less fucked than what I was a few hours ago :)

Thanks a lot, again!

Name: Anonymous 2007-05-11 0:01 ID:wB96rNJd

Glad you're more comfortable.

It's been years since my first C++ final. I do remember that in a 10 question setting, there's some stuff on implementing a simple function like factorial (well, something similar to it, to test your recursion skills. Not mentioned above, but recursion is important.) The class may quiz you on examinining a "mystery function" and briefly describing what it does.

If you can't figure it out, (hell, even if you know,) explain the return values, a little bit about the internal processing of the inputs, and anything peculiar of the inputs, such as "takes a floating point number instead of an integer, so it may be meant to process currency" or temperatures or something.

You will probably be tested on a simple string function as well. Though you are expected to write code, don't fuss over forgetting semicolons. It's more important that use use standard  goodwill practices, like liberal commenting, longer variable names, and if you can't understand how to do something, just put comment marks and say "I forgot exactly exactly which file has the function to get the system time." Wordy stuff is better because the graders aren't mind readers but will sympathyze with people who know content but can't look it up during an exam.

In real life (well, in higher classes too) you'll be expected to know where to look up references, or share code (read other people's or write for other people.) I mention this because it's the reason some Comp Sci classes give you open book tests, knowing that a problem given isn't 100% in the book, but that you can figure it out from the book if you remember where the knowledge was. It's the equivalent of today's googling, which is fair and square in the real world.

Again, good luck!
As an aside, if your midterm wasn't 10 questions, and you need more reference, you can probably google for C++ final exam or something. I'm sure you'll find professors who upload their earlier finals for their students and just change the numbers and one or two functions. Question wise, be expected to know about initializing a char array or using new and delete. The object part of C++ isn't too important yet, until you take data structures. That means that at most you'll get one question about "how do I create a linked list out of node objects" or something. Actually, that kind of question appears over and over in more detail as you advance.

Name: Anonymous 2007-05-11 10:38 ID:/xPOmpOT

I've never been to college, i study C for 3 years and i propably know more than any student in a college.
fucking n00bs.
I bet this idiot doesn't know how a structure or even an array looks in memory or what a pointer is.
Or that break/continue are infact jmp's like if and while.
Or what typecasting does, or the difference between ASCII and a numeral system.
Or maybe that FILE is not a type, but a structure.
Or that sizeof() is not a function.

Simple shit, that everyone should know but they don't because they're in a hurry to code their own WoW in C++.

Name: Anonymous 2007-05-11 11:27 ID:n3rgoS2n

>>11
Wow, you're pretty sandcore. Was the whole point of your post really just to brag with your C trivia?

(I've used C for 10 years and happen to be in a college right now.)

Name: Anonymous 2007-05-11 11:50 ID:Heaven

>>12
Fifanit lafeli.

Name: Anonymous 2007-05-11 11:52 ID:Heaven

>>13
Etaoin shrdlu.

Name: Anonymous 2007-05-11 11:52 ID:n3rgoS2n

>>13
That's my line, bastard.

Name: Anonymous 2007-05-11 14:59 ID:y+7DorKu

SANDCOAR

Name: Anonymous 2007-05-11 15:46 ID:Heaven

>>16
lol DorK

Name: Anonymous 2007-05-11 16:54 ID:pFslNcbh

>>11
Do you realize how dickhead you are ?

Name: Anonymous 2007-05-11 18:35 ID:Heaven

>>11
DICK-WAVING CONTEST, GO

Name: Anonymous 2010-12-26 7:22

Name: Anonymous 2011-02-03 6:07

Name: Anonymous 2011-02-03 7:49

Name: Sgt.Kabuゥ棝kiman諬谒 2012-05-29 1:34

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List