I have a current assignment I'm trying to finish by tomorrow but I'm totally clueless as to how I can fully "build" this program.
I'm currently working with Pointers and Dynamic Arrays and I don't have the slightest clue on what they are. I've tried looking online for definitions but none of them were given in simple terms.
I'm supposed to create a program that creates 10 random numbers and then print them out. After printing them out, I have to sort them in ascending order using bubble sort. After sorting I'm supposed to print out the sort and be done with the program.
I've split it into three files (Header file, Implementation file, and Main)
The problem is I really don't know how to fully build each file and then connect them together.
#ifndef Asst3
#define Asst3
class Arraysort
{
private:
int * array ; // pointer for array
int size ;
bool sorted ; // unset in Constructor, set in sort_array()
public:
bool is_sorted(void) ; // getter for sorted
int get_size(void) ; // getter for size
void load_array(int n) ; // load with random numbers mod n
void print_array(void) ;
void sort_array(void) ; // bubble sort
Arraysort(int n ) ; // Constructor
~Arraysort(void) ; // Destructor
} ;
#end if
float * D ;
A = (float*) malloc(count*sizeof(float))
Free (D) ;
Whats A ? And in c++ use new not malloc.
like d = new float[5];
I'm currently working with Pointers and Dynamic Arrays and I don't have the slightest clue on what they are.
When you are creating array you must know its size: int array[size];
where size must be value, known before compilation.
But what if you don't know how many elements will me generated, or written by user? Then you create a pointer int *pointer;
And when program is running you can allocate memory by using new and assign returned pointer to *pointer. pointer = newint[size];
in this case size doesnt has to be constant\
I'm sorry. I really do not know what A would be and how to use new in the Main File. I'm really new to C++ and I'm trying my best to understand all of it. You might have to dumb it down for me.
I've been trying to go through numerous online resources and trying to look at their code to change and implement into my own. It seems like I created more of a mess than a beginning.
Don't be sorry, because it won't help you. You are trying to rush through it too much.. start some c++ tutorial and do all exercises.
Programming is really simple with good approach: I'm supposed to create a program that creates 10 random numbers and then print them out. After printing them out, I have to sort them in ascending order using bubble sort. After sorting I'm supposed to print out the sort and be done with the program.
1. creates 10 random numbers and then print them out
2. sort them in ascending order using bubble sort
3. print out the sort
Once known, sit for an hr, read new and delete function, rand function and bubble sort, then you can write ur program in a few minutes, code is not important, but concepts are!!!
I'm trying to write it as a C++ program in code::blocks 10.05
To anirudh sn:
I'm also currently watching introduction to C++ videos online to grasp the foundation of the programming. I have the purpose of the program down, but use of each code and what other codes that are out there, are the things that really tears me to pieces.
So far, I know that the header file declares/defines the objects I'm using (right?), and the implementation file holds the back ground functions that use the objects from my header file. Lastly, the main file is where I put them all together and give it the final organization.
I'll do as anriudh said and re-look at the codes I'm using.
I would be pissed if I were your teacher and I gave the instructions: "create a program that creates 10 random numbers and then print them out. After printing them out, sort them in ascending order using bubble sort. After sorting print out the array and be done with the program." and you gave me something with classes.
Thank you for your help, Lowest One, but the header with the class file was given by my teacher. That code you see is directly stated by him. I was allowed to separate the program into numerous file or compact them all into one.
I wish to apologize that I did not include that earlier in my first post.