mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

FirstPerson... I think the OP asked for a nested for loop :P

Oh ok :

for(int i = 0; i !=1; ++i){
    cout << "M"<<endl;
for(int thisIsStupid = 0; thiIsStupid != 0; );         
}
Nick Evan commented: Best. Code. Ever. +10
mrnutty 761 Senior Poster

???

for(int i = 0; i !=1; ++i)
    cout << "M"<<endl;
mrnutty 761 Senior Poster

don't use the sqrt function. compare the squared distance.

mrnutty 761 Senior Poster

They will pretty much teach you the same thing at least the concept part,
like loops, if else statements, control flow, variables, ints, floats ,blah blah
blah.

I think if you take C++, then picking up C by your self is not hard. If you
had to pick 1 , I would suggest picking C++, if you wan't to take both,
then go ahead. If both of these class becomes a big load to handle,
then drop 1 of the, I suggest C.

mrnutty 761 Senior Poster
#include<iostream> /**/
#include<string>
using std::cout; using std::string; std::ostream& _H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G = cout;
/******************************************************************//**/
string _____("H       H         A         P P P P   P P P P   Y    Y\n");
string _______________("   T                 G  G  G     I I I         V       I I I     N     N    \n\n\n");
string ______("H       H        A A        P     P   P     P    Y  Y\n");
string ______________("   T               G   G   G       I          V V        I       N   N  N   \n");
string ________("H       H      A     A      P         P           Y\n");
string _____________("   T               G   G   G       I          V V        I       N   N  N   \n");
string _________("H       H     A       A     P         P           Y\n\n\n\n");	
string _______("H H H H H       A A A       P P P P   P P P P     Y\n");
string __________("T T T T              G G G G     I I I     V       V   I I I     N       N  \n");
string ___________("   T                G              I        V     V      I       N N     N  \n");
string ____________("   T   ---------   G     G         I         V   V       I       N  N    N  \n");

/******************************************************************/
int main()/**/
{
							_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_____;
							_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<______;
	_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_______;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<________;
	_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<__________;
	_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<___________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<____________;
	_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_____________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<______________;
						_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_______________;


}
MosaicFuneral commented: lol, That's some sweet shit! +0
mrnutty 761 Senior Poster

Since thanksgiving is soon here, I thought we would have our
own daniweb feast, specifically an obscure feast. Remember that
only obscure code is valid in our obscure table.

I'll start :

#include<iostream> 
#include<string>
using namespace std; ostream&  ____ = cout;
string _____ = "hello";string
______	("world");		string
				_______
   ("obscure");char _
		(' ');	char __('\n');
int main()
			{
			____<<
_____<<				 _  <<

		   _______<<	_<<	
  ______<<				__; 
	
			}
mrnutty 761 Senior Poster

The function uses the & operator. That operator makes a variable
synonym.

For example :

int num = 10  ;
int &ref_num = num;
ref_num = 4;   //same as doing    num = 4

So similarly, since this function :

istream& read(istream& is, Student_info& s)

Take a look at this part :

istream& is, Student_info& s

What ever we pass to that function ( assuming its acceptable),
is becomes a synonym, and s becomes a synonym.

So say this is how we call the that function

read( cin,  anStudentObject ); //function call

Since the prototype is :

istream& read(istream& is, Student_info& s)

and since cin is a istream object, and anStudentObject is a Student_info object, that function call is acceptable.
You remember what the & operator does right? Passing in , cin and
Student_info makes the variable, "is" and "s" synonym to cin and anStudentObject , respectively. So using the "is" variable is like
using the cin variable, its just a different name. Ok?

The reason it returns a istream object is to show you that it can.
And when you get to operator overloading you will see the significance
of it.

But know that you can do this :

Student_info& student;
//...insert info into s

//call your read function and since it returns an object, we can use it cin again
read(cin , student).clear()
mrnutty 761 Senior Poster

This shouldn't be this hard.

You want to read from a text file of the format :

Firstname;Lastname;178

where the ';' means the word has ended. And you know you will
always read firstname, then lastname, then the value. Now first
you need to open a file. Of course you know how to do that :

ifstream getFromFile("text.txt");

That opens a file to read. Now you have to read.

First lets say this is the file :

Firstname;Lastname;000
Tony;Montana;100;
Best;Forever;99;
Richard;Jones;98;
World;Hello;97;

You now need to read the file. What you can do is read 1 line into a string. Then have a function find all occurrence of ';' and replace it with a space.

Here is a complete example :

#include <iostream>
#include <string>
#include <fstream>
#include <vector>


using namespace std;

//find wherever ';' is and replace it with ' '
void wordReplace(string& source,char find = ';', char replaceWith = ' ')
{
	size_t pos = 0;

	while(true)
	{		
		pos =  source.find_first_of(find,pos);	 //find the position of ';'
		if(pos == string::npos)
			break;
		source[pos] = replaceWith; //replace ';' with a space
	}

}
int main() 
{	
	ifstream iFile("test.txt"); //open file to read
	
	if(!iFile) return -1; //check if file is opened

	string word = ""; 
	
	vector<string> fullNameWithValue;
	
	while( getline(iFile,word)) {		 //get a line into a string
		wordReplace(word); //replace ';' with ' '
		fullNameWithValue.push_back(word); //add word to out list
	}

	for(size_t i = 0; i < fullNameWithValue.size(); i++) //print out word
		cout<<fullNameWithValue[i]<<endl;

	 	
	return 0; …
mrnutty 761 Senior Poster

In my free time I kick puppies and shoot kids with a paintball gun.

Sounds like a good hobby? Is there a team to join for this sort of
stuff.

mrnutty 761 Senior Poster

Just wondering what other programmer do in their free time.

This is basically what I do in my free time :

1) Procrastinate ( of course )
2) Try to learn more things about programming
3) Practice programing
4) Play NBA2k9 and/or Call of Duty : modern warfare 2 (awesome games)
5) Chill with friends and laugh at stupid things
6) Maybe do some school work.

mrnutty 761 Senior Poster

You can use the .exe file in your project directory.

Intrade commented: I don't know why but this remark to the OP is oh-so-funny XD +0
mrnutty 761 Senior Poster

For that you need to read multiple books, and even then you won't know
everything. But to start out, C++ primer plus is a good book. It goes in
details of C++.

jonsca commented: That is a good book, one of the most underrated on the market I think. +1
kvprajapati commented: Good advice. +6
mrnutty 761 Senior Poster

replace the && with the ||. You wan't the loop to run if either currentX OR currentY is not equal to toX or toY, respectively.

Also take out the

else { currentX-- } and else{ currentY-- }

there is not point since say currentX will not increment if its 100.

mrPaul commented: very good advise +0
mrnutty 761 Senior Poster

The simplest sort, although inefficient. Below is a demonstration of
bubble sort and insertion sort.

The bubble sort just consists of 2 for loops and std::swap.

The insertion sort uses 2 loops as well but not as much swap
as bubble sort.

Any questions ?

Ancient Dragon commented: Great job :) +25
mrnutty 761 Senior Poster

It is converting it correctly. It just doesn't display the trailing 0's.

If you want to see the trailing 0's then you can use DecimalFormat

mrnutty 761 Senior Poster

When the can of frozen Orange juice says "Concentrate" and you do.

Oldy!

When you give out your number to girls in binary.

iamthwee commented: Never give out your number, always get theirs. ;) +0
mrnutty 761 Senior Poster

I have a question. Lines #21, #22 and #23:

employee *first=NULL;
first=new employee;
if(first==NULL){
//...

If you allocate memory for pointer 'first', is that possible for 'first' to be NULL unless you get some exception?

Yes, but what he is doing is wrong. If you use nothrow
when allocating for memory, then first could be null, if it failed to allocate memory.

like this :

int *p = new(nothrow) int[100000000];
if(! p ){
cout<<"Error allocating memory\n";
}
else cout<<"good\n";
mrnutty 761 Senior Poster

From what my debugger is telling me, you have a stack overflow on line 544

mrnutty 761 Senior Poster

The function adds two large numeric string together, like "12345667" + "12345678" = ?

It does not have complete error checking, I'll leave that up to you.

It should work but I am prone to bugs, so do advise if bugs are found.

Included are also helper function that helps us add the large numeric string

mrnutty 761 Senior Poster

but my teacher wants the user to be able to be able to input a number of [B]any [/B]length

That means that you shouldn't use int, double , long long or whatever.
It means you should get your input as a string in order to have any length.
Primitive data types have limits on the max and min range of number
they can represent, but my teacher wants the user to be able to
be able to input a number of any length"]More Info on that.

mrnutty 761 Senior Poster

Good. Now try to be more organized and start learning classes. Once you
have a "good" grasp, convert the code into objects.

mrnutty 761 Senior Poster

You know you are a geek you find it more natural to count numbers
in the power of 2 then decimal.

William Hemsworth commented: nice thread. +0
mrnutty 761 Senior Poster

use SingletonVector::vBooks.push_back(b);

pac-man commented: Thanks for the replies mate +1
mrnutty 761 Senior Poster

Don't use goto. Period.

How about you show some code and explain what you are trying to do

mrnutty 761 Senior Poster

You forgot to enable GL_COLOR_MATERIAL, when using lighting. I
changed it a little, take a look at the comments.

#define GLUT_DISABLE_ATEXIT_HACK
#include <stdlib.h>
#include <GL/glut.h>


// Globals
void display();
void myInit();
//Set up material
	GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
	GLfloat mat_ambient_color[] = { 1,1,1,1 };
	GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat no_shininess[] = { 0.0 };
	GLfloat low_shininess[] = { 5.0 };
	GLfloat high_shininess[] = { 100.0 };
	GLfloat mat_emission[] = {1,1,1,1};

//Set up lighting
	GLfloat light0_pos[]={20.0, 100.0, 1.0, 0.0};
	
	GLfloat diffuse0[]={1.0,1.0, 1.0, 1.0};
	GLfloat ambient0[]={0.4, 1.0, 1.0, 1.0};
	GLfloat specular0[]={1.0, 1.0, 1.0, 1.0};

	GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 };
   GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
   GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
   GLfloat local_view[] = { 0.0 };
   GLfloat global_ambient[]={0,0,0,0};

void myReshape(int w, int h);
void drawSphere();
GLsizei wh=800, ww=800;

void myInit()
{
  
   glClearColor(0.7f, 0.9f, 1.0f, 1.0f);	// Set background color to sky blue.
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);

   glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
   glLightfv(GL_LIGHT0, GL_POSITION, position);

   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
   glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_NORMALIZE);	
	//NEW
   glEnable(GL_COLOR_MATERIAL);

  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_ambient);
  glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
}


void display(void)
{	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

//Draw sphere
   glPushMatrix();
   glTranslatef (-4.0, 5.0, 0.0);
   glColor3f(1.0f,1.0f,0.0f); …
mrnutty 761 Senior Poster

Here's my code.

int main ()
{
   int input;
   cout <<"Enter a sequence of numbers (0 to quit): ";
   cin >> x;

   if (x != 0)
   {
     if (x % 2 == 0)
      {
         cout << x << " is even" << endl;
      }
      else if (x % 2 != 0)
      {
         cout << x << " isn't even" << endl;

      }
  }
}

Your almost there :

1) change : int input; TO int x;
2) Wrap your code in a do while loop.

int x = -1;
do
{
  /* get user input and check for even/oddity */
}while(x != 0) //quits if user enters 0
Towely commented: You rule! Thank you so much! +1
mrnutty 761 Senior Poster

First have the object ready to fire, meaning have the object at the position
of where its going to be launched.

Then you could do something like this :

Ball.y += ball.velY;
Ball.x += ball.velX;

Have the velX faster than velY;
Then you need to change velY and VelX;
You could do something like this :

Ball.velX += Ball.InitialVelocity - Ball.accel * Ball.time
Ball.velY += Ball.InitialVelocity - Ball.accel * Ball.time

Your ball.accel is just gravity.

mrnutty 761 Senior Poster

Ah, ok. I tried this...but it still doesn't work:

......
	if(info == 'c')
	{
		gauge[0]='C';
		gauge[1]='F';
		values(float value1[11]);
		for(int x=0;x<=10;x++)
			value2[x]=(value1[x]*9)/5+32;
	}
	else
	{
		gauge[0] = 'F';
		gauge[1] = 'C';
		values(float value1[11]);
		for(int x=0;x<=10;x++)
			value2[x] = ((value1[x] - 32) * 5)/9;
	}
...............

your function call should be :

values(value1);
mrnutty 761 Senior Poster

Just for trial, try putting :

using namespace SAMSErrorHandling;

at the top of your main.

mrnutty 761 Senior Poster

Hven't tried it out and its about 3 am but I'll give it a shot :

I will build up :

CASE A : First to create a 1d array :

const int NODE_SIZE = 5;
Node * p = new Node[NODE_SIZE];

CASE B : Now to create a 2 d array you need to have each of the node
element carry some more node element.

const int NODE_X = 5;
const int NODE_Y = 5;
Node **p = new Node*[NODE_X];

//each node_x needs its own node y to create a 5x5 2d array
for(int i = 0; i < NODE_X; i++){
        p[i] = new Node[NODE_Y]

CASE C: //For a 3d array each node has to has NODE_Y element and each
NODE_Y element has to have its NODE_Z element

const int NODE_X = 5;
	const int NODE_Y = 5;
	const int NODE_Z = 5;
	
	//currentl 1d array
	Node*** p = new Node**[NODE_X];
	//now a 2d array
	for(int i = 0; i < NODE_X; i++){
		p[i] = new Node*[NODE_Y];		
	}
	//now a 3d array
	for(int i = 0; i < NODE_Y; i++)
	{
		for(int j = 0; j < NODE_Y; j++){
			p[i][j] = new Node[NODE_Z];
		}
	}

For case A ( 1 D array ) you can access and write data like this :
Node = ...

For case B (2d array) you can access and write data like this :
Node[j] = ...

For case C( 3d array) you …

mrnutty 761 Senior Poster

>>WHAT IS WRONG WITH THIS CODE?
1) You do not use code tags
2) You haven't included the necessary library
3) I don't think you understand what the question is asking, so
understand it before you write the program.

I'll try to break the question down for you :

Write a program that uses cin to read a given name (like Louis) and a family name (like Armstrong) into two string variables, given and family. 
//Meaning you have 2 string variables called family and given, and 
//you need to ask the user to input a first name and a last name

The program then makes assignments to two other string variables: givenFirst and givenLast. To givenFirst it assigns the concatenation of given, a space, and family. 
//means that you need 2 other string variables called givenFirst and 
//givenLast. And to givenFirst you need to concatenate or add the 
//string variable given, a space and the string variable family.
//Here is an example : 
string givenFirst = given + " " + family

To givenLast, it assigns the concatenation of family, a comma followed by a space, and given.
//same concept as above, try it out.
Sky Diploma commented: Nice!! +3
mrnutty 761 Senior Poster

Try this :

double norms(double vectorA_xcomponent, double vectorA_ycomponent, double vectorA_zcomponent, double& norm_1)
{
    norm_1 = (vectorA_xcomponent+vectorA_ycomponent+vectorA_zcomponent);
    return norm_1;
}

Change the prototype as well.

mrnutty 761 Senior Poster

>>1) The format the user should be entering his matrice should be:
1 2 3 4 5 6 7 8 9 'ENTER'
right now it is 1 'ENTER', 2 'ENTER', 3 'ENTER' ... etc all the way to the 9th number.

what happens if you just put 1 2 3 4 ... <enter> as your input, it should work.

2) if you look at the output I am currently getting at the bottom of my first post you will see that there is a '+' sign and an '=' sign after each row, i need to make it so that there is only 1 of each aligned with the center row.

so you want :

1 2 3      1 2 3     2 4 6 //and so on 
4 5 6  +  4 5 6  = 
6 7 9       7 8 9

if so then just do a test case(i.e if/else) when row is 2 and column is the last column.

if(row == 2 && col = lasCol)
   cout << A[i][j] <<" + " << endl;

for the other matrix you would have to change the plus to equal sign.

mrnutty 761 Senior Poster

>>1) the style in which the user inputs their numbers for each 3x3 matrix should be - enter all 9 #s and then press enter... as opposed to enter a # press enter (9x)

Ok, whats the problem with this?

>>2) the only place i know where to put the '+' and '=' sign makes it print each time... where should i place it to only print in the center of the Matrices?


not sure what you mean?


>>3) part of the assignment is to use the void function, i never utilize it in my main, im lost as to where exactly i should put it in

that void function adds matrices, so call it before you print out all the
result, like addMatrices(matrix1,matrix2,resultMatrix);
then you can print out the results.

mrnutty 761 Senior Poster

print out the sum, cout<<sum << endl;

mrnutty 761 Senior Poster

>>I'm storing base class pointers in a vector, the pointers are pointing to objects from the derived class ( Leads ).
>>I'm unable to access the 'getter' functions of the derived class. How can this be done?

It seems like you need the use of virtual functions. The error message says what it means, you have not defined a getDate function in you
base class.

Here is an example of something that might help you :

#include <iostream>
#include <vector>
#include<string>

using namespace std;


class Base{
private :
	string name;
public:
	Base() : name("") { };
	Base(const string str) : name(str) { };

	virtual const string getName() {
		return name;
	}
};

class Derived : public Base{
	string myName;
public:
	Derived() : Base(), myName("") { }
	Derived(const string derStr) : myName(derStr) { }
	Derived(const string baseStr, const string derStr) : Base(baseStr) , myName(derStr) { }
	const string getName() {
		return myName;
	}
};
int main()
{  
	vector<Base*> baseVec;	
	Base b1("base 1");
	Derived d1("derived 1");
	Derived d2("derived 2");

	baseVec.push_back( &b1);
	baseVec.push_back( &d1);
	baseVec.push_back( &d2);

	for(unsigned int i = 0; i < baseVec.size(); i++){
		cout << baseVec[i]->getName() << endl;
	}
	return 0;
}
Carrots commented: Thanks ever so much buddy! :) +1
mrnutty 761 Senior Poster

#include<iostream>
#include<windows.h>

int main(){
   string str = "hello";
    cout<<str<<" ";
    Sleep(1000); //wait 1 second
     cout<<"world\n";

 return 0;
}
mrnutty 761 Senior Poster

How to declare an array in c++ :

int Array[4] = {1,2,3,4};
const int SIZE = 6;
float Array[SIZE] = {0}; //set all elements to 0
char Array[5] = {'1','2','3','4','\0'}; // "\0" is the null character and an array of char should end with it.

int Array[]; // invalid form
int[] Array; //invalid form
mrnutty 761 Senior Poster

1st) Read post 1, although if you PM, someone that knows a little math, he might help you.

2)

Let A = r+5(r-2)=28
Let B = 3(r+4)+5(r+2)=102 


//Break down A
A = r+5(r-2) = 28
= r + 5r - 10 = 28 //distributive rule
= 6r - 10 = 20 //add like trms
= 6r = 20 + 10  //remember switching numbers to the opposite sides mean change its operatorion from + to minus, * to / and vice-versa
so, 6r = 20 + 10,
6r = 30
r = 30/6 = 15/3 = 5
//Break down of B
Let B = 3(r+4)+5(r+2)=102 

B = 3r + 12 + 10r + 20 = 102 //Distributive property
=  3r + 10r + 12 + 20 = 102 // re-arrange like terms
= 13r + 32 = 102 //add like terms
 = 13r = 102 - 32 //bring together like terms
 = 13r = 70
 = r = 70/13
iamthwee commented: very cute. +11
mrnutty 761 Senior Poster

>>Is there any way to stop the axis from rotating but allowing the object to translate or is there a trick to get around this.

Yes, use push and pop matrix for that, as well as return the original coordinate back in place , see below :

//save current matrix for only the code between the push/pop
glPushMatrix();
//rotation code here
glPopMatrix();

And when you want to reset coordinates, after translation to an object,

glTranslatef(x,y,z); //moves object to a certain coordinates
//blah blah
glTranslatef(-x,-y,-z); //resets the coordinate back to its regular position, thus the blah blah has its own relative positioning.
mrnutty 761 Senior Poster

char arrURI[1]; -- creates an array of size one
-- so there are two indexes 0 and 1

Actually there is only 1 index, which is 0 in char A[1];
A[0] = 'a'; //ok
A[1] = 'b'; //bug

mrnutty 761 Senior Poster

which part do you need the help with?

Mean = average = Sum of Total elements / Number of elements

Median is the middle number in a sorted set of numbers

Mode is the most occurring number.


To find the Mean you can sum up the total and divide by the vector size
To find the median you need to sort the vector. Then check if the vector size is even, if so then you could do the following :

int Indx = vec.size() / 2;
float median = ( vec[Indx] + vec[Indx+1] ) / 2;

if you vec size is odd then you can simply do this :

float median  = vec[ vec.size()/2 ];

You can count up the frequency of each number if the array after you
are done.

mrnutty 761 Senior Poster

Wow, this is funny. Hey, I have a lot of exams right now and I am
broke, can you just give me couple of thousands of dollars, so I don't have
to work? Just mail it to me.

mrnutty 761 Senior Poster

there is a lot of logic errors, but this one is a compile time error :

cin << yesorno;

you mean cin >> yesorno , right.

mrnutty 761 Senior Poster

How about you explain this code. Tell me what each line does.
Then tell me what you think you need to do in order to duplicate a word.

void duplicateWords (nodeType*& first, nodeType*& last)
{
 
struct nodeType *i;
int wordCount = 0;
 
for (i = first; i->link != NULL; i = i->link)
{
char temporaryWord[3];
 
if (i->link->info == temporaryWord[i])
 
wordCount++;      
}    
 
 
}
mrnutty 761 Senior Poster

Try this. And inline won't do anything helpful by the way.

ostream& operator << (ostream& os, FixedSizeMatrix& obj)
{
   obj.print(os);
   return os;
}
mrnutty 761 Senior Poster

Normally with destructor and constructor,
you should do something like ,

Array(){
  mainArray = new Type[0];
}
~Array(){
  delete [] mainArray;
}

Here is a complete example.

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

template<typename Type>
class Array
{
	typedef unsigned int uInt;
private:
	uInt len;
	Type * mainArray;
public:
	Array(){
		mainArray = new Type[0];
		len = 0;
	}
	Array(uInt Sz, Type val){
		mainArray = new Type[Sz];
		len = Sz;
		for(uInt i = 0; i < Sz; i++)
			mainArray[i] = val;
	}
	~Array(){
		//Its able to delete a null pointer, i.e if(len == 0);
		delete [] mainArray; 
	}
	bool isEmpty() {
		return len == 0; 
	}
	uInt Size(){
		return len; 
	}
	bool Print(int col)
	{
		if(!len) 
			return false;

		for(uInt i = 0; i < len; i++) {
			if(i && i % col == 0) 
				cout << endl;			
			cout<<mainArray[i]<<" ";
		}
		
		return true;
	}
	
};

int main()
{  
	Array<int> Numbers;
	Array<float> Numerics(12,10);

	cout<<"Numbers size is : " << Numbers.Size() << endl;
	cout<<"Numerics size is: "<< Numerics.Size() << endl;
	
	if(Numbers.Print(4))
		;
	else cout<<"Nothing to print in Numbers\n";

	cout<<endl;

	if(Numerics.Print(4))
		;
	else cout<<"Nothing to print in Numerics\n";
	
	cout<<"\n\n";


	return 0;
}
mrnutty 761 Senior Poster

It seems like you are trying to make a code to send somebody a
harmful .exe.

Therefore I will not tell you.

If i am wrong then say so, trusting you not to lie.

tomtetlaw commented: Good Thinking :) +0
mrnutty 761 Senior Poster

There are basically the same except for their accuracy.

A float is for example the following :

float F = 3.1415f;

And a double is the following :

double D = 3.1415;

As you can see they are similar, the only difference comes when
accuracy is in play. A double can handle a lot more accurate digits
than a float can.

Usually, a float is good enough to use, than of a type double.
If you don't care about accuracy that much, for example, if
PI = 3.1415972f, is enough accuracy then a double would not be needed. A double will consume more memory than a float will.