mrnutty 761 Senior Poster

Consider separating the 1's and 0's with whitespace.
Otherwise, you may need to read each character as a char and convert to its equivalent digit.

the file contains 3 lines of 1,000 integers. That will be a waste of time
if you want to separate each int with white spaces.

just read it as a char, like he suggested. Then subtract '0' from it
to get the int value. Something like this :

char c;
ifstream iFile("num.txt");
int i = 0;
while(iFile.get(c) && i < 1000)
{
     int num =  c - '0';
    myArray[0][i] = num;
     i++;
}
mrnutty 761 Senior Poster

but we are told that we need to use recursion in this code...

Damn it. Please try to ignore my prev post. I thought this was
just a practice problem. Please do try to do this on your own.
I feel it coming soon.

mrnutty 761 Senior Poster

Here is a recursion version. Try to make it non-recursion.

//row is the number of rows
//itr is the number of column (sort of)
void prnt(int row = 5,int itr = 1)
{
	if(itr >= row)
		return;

	for(int i = 0; i < itr ; i++)
		cout<<(i+1);
	
	cout<<endl;

	prnt(row,itr+1);
}
mrnutty 761 Senior Poster

Divide and conquer. Think about those words.

When trying to create algorithm,

I) you will get better as you gain more experience.
II) Think about the algorithm in parts. What do you need
to happen first. Then go step by step. Its a simple step but
its really powerful.
IV) Practice

mrnutty 761 Senior Poster

To be a expert programmer rating 10 out of 10, you have to be
born to program. But fortunately, there is 9.99. To achieve that
rating from range 1 - 10, you have to study and work hard like
everything else in this world. One thing I will tell you is read read
and read more books. For C++, my suggestion is to read C++
Primer Plus 5th edition. Its a good start. FORGET about
learn X language in X days. Its not good enough.
Keep it up. As time goes one you will get used it to, and sooner
or later you will realize the power of C++, its a true beast.
Then after you have a solid understanding about C++,
ranges from few years to decade, go on to other language and
diversify. In fact you might want to diversify your language
in a year or two.

mrnutty 761 Senior Poster

If you didn't realize this code :

int numX;
    int numY;
    int numZ;
    
    int sum1 = numX - numZ;
    int sum2 = numX - numY + numZ;
    int sum3 = numX + numY;
    
    int sum4 = numX + numY + numZ;
    int sum5 = numX;
    int sum6 = numX - numY - numZ;
    
    int sum7 = numX - numY;
    int sum8 = numX + numY - numZ;
    int sum9 = numX + numZ;
    
    int totalA = sum1 + sum2 + sum3;
    int totalB = sum4 + sum5 + sum6;
    int totalC = sum7 + sum8 + sum9;
    int totalD = sum1 + sum4 + sum7;
    int totalE = sum2 + sum5 + sum8;
    int totalF = sum3 + sum6 + sum9;

Is useless because numX,numY,numZ is not initialized. You need
to first get num* then calculate it. What you are doing is
calculating junk, then getting num* then showing the junk you
calculated.

Again get user input first into numX,numY,numZ, then calculated
whatever you need to calculate.

-------
num* = numX, numY, numZ

mrnutty 761 Senior Poster

What is the purpose of using call by value and call by reference?

Again :

A side note : one of the main reason call by reference was created is
because passing a class object by value is expensive.

You can think of Pass by reference like a pointer in disguise.

Pass by reference is a pointer under the hood.

mrnutty 761 Senior Poster

another example :

typedef float data_type; 

data_type mySumRecursive(vector<data_type> vec, data_type * s,int strt = 0)
{
	if(strt == vec.size())
		return vec[strt-1]; 

	 *s +=  vec[strt];

	 mySumRecursive(vec,s,strt+1);
}
mrnutty 761 Senior Poster

Basic encryption, i.e weak but encrypted.

1) Read file content into string
2) Have a key number, say 5.
3) Shift all letter in the string by adding the key number

for(int i =0; i < string.size(); i+=) string[i] +=key_number

4) Now its encrypted.
5) For decryption, just using the same for loop but instead
do string -=key_number.

mrnutty 761 Senior Poster

"finding parts of files."

No, not finding parts of the file but read the whole file, while
analyzing it in the process.

Assuming the file is the something like this :

Info.txt
---------------------------------------------
Password = hello_world
Active t = false
---------------------------------------------
1) open up a file with fstream
2) read first line into string
3) increment the string until it reaches the equal sign, then the password something like this :

while( *stringVariable++ != '=' ) ; //increment until the = sign
while( ! (isalpha (*stringVariable++) ) ); //increment untill you reached the first letter in the password.

4) Now you have got the password. save it.
5) read the next line. do the same process like in # 3
6) compare stringVariable to flase or true. Set bool variable
accordingly.

7) Continue with the rest of your program.

mrnutty 761 Senior Poster

Here are some problems. Easy to harder from my stand point.

1) hello world
2) Advance calculator
3) RPG game
4) your own string class
5) your array class
6) single linked list
7) array class using linked list
8) double linked list
9) Praiser
10) ...out of ideas


Printing shapes
a) Draw a square
b) Draw right triangle
c) Draw diamond
d) Draw Christmas tree
e) Draw a diamond inside a square

Recursive
I) create recursive adding function that returns a multiplication of paramerter a and paramerter b
II) create recursive factorial function (no cheating)
III)create recursive Fibonacci (no cheating )
IV) create recursive string.reverse function, that reverses a char *str, recursively.

mrnutty 761 Senior Poster

Thanks for helps. Can you tell me how can I fix it?

double avg_file(ifstream& source_file)
{
	double number_in_file;
	double total = 0;
	int count = 0;
	while (source_file >> number_in_file)
	{		
		total = number_in_file + total;
		count ++;
	}	
	//average of numbers in file
	return (count);	
}

http://www.daniweb.com/forums/post155265.html#post155265

Pay attention.

mrnutty 761 Senior Poster

Nested class means that a class is "nested" i.e, in scope of
the outer class.
Thus the code :

class Outer
{
public:
    class  Inner{ ... };
}

has a nested class called Inner because its inside the scope of the
outer class. And if public, it could be used with the scope resolution operator ::, like so Outer::Inner::someFunc

mrnutty 761 Senior Poster

Are you including other header file that has classes?

If so then the class is probably missing a semicolon at the end of
its definition.

class A
{ ... 
} ; <--- need semi-colon?

If you do not have class defined in other header file, then something is missing a semi-colon.

mrnutty 761 Senior Poster

Because its inside the class definition. Technically, you can access a
class data member , if you are trying to access it inside its definition.

Think of class B like a member function accessing its private data,
except its a class instead of a function.

mrnutty 761 Senior Poster

Here is a sample app via openGL. Terrian

1) Press ',' the comma key to get a outline view.
2) Press space bar about 15 times or so, to displace the land.
3) press 'c' to smooth out the land.

Its one of my earlier project.

mrnutty 761 Senior Poster

Try it.

mrnutty 761 Senior Poster

Proper indent!

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void main()
{
      FILE *fp,*ft;
      char another,choice;

struct emp;
{
      char name[40];
      int age;
      float bs;
};

      struct emp e;
      char empname[40];
      long int recsize;

      fp=fopen("EMP.DAT","rb+");
      
      if(fp==NULL)
      {
            fp=fopen("EMP.DAT","wb+");

            if(fp==NULL)
            {
                  puts("cannot open file");
                  exit(1);
             }
      }

      recsize=sizeof(&e);

      while(1)
      {
            clrscr();
            gotoxy(30,10);
            printf("1.Add records");
            gotoxy(30,12);
            printf("2.List rcords");
            gotoxy(30,12);
            printf("0.Exit");
            gotoxy(30,20);
            printf("Your choice");
      
            fflush(stdin);
            
            choice=getche();
      
            switch(choice)
            {
                  case 1:
                              fseek(fp,0,SEEK_END);
                              another='Y';
                              while(another=='Y')
                              {
                                    printf("\nEnter name,age and basic salary");
                                    scanf("%s%d%f",e.name,&e.age,&e.bs);
                                    fwrite(&e,recsize,1,fp);
                                    printf("\nAdd another record(Y/N)");
                                    fflush(stdin);
                                    another=getche();
                              }
                              break;
            
            case 2:
                        rewind(fp);
                        while(fread(&e,recsize,1,fp)==1)
                        printf("\n%s%d%f",e.name,e.age,e.bs);
                        break;
            
            case '0':
                              fclose(fp);
                              exit(0);
                  }
      }
}
mrnutty 761 Senior Poster
int num[10] = {5,3,-1,2,5,12,42,-35,-2,0 };
std::sort(num,num+10);

Try this link : google

mrnutty 761 Senior Poster

A side note : one of the main reason call by reference was created is
because passing a class object by value is expensive.

You can think of Pass by reference like a pointer in disguise.

mrnutty 761 Senior Poster

1) GOOGLE it

2) use std::sort function.

mrnutty 761 Senior Poster

okay, i understand...juz wanna ask...is it possible to create a huge array then minimize the array according to the users input...
for example

game[500][500];
then minimize from there...

I think what you are looking for is vector or this vector

They have the capability of resizing to whatever size you would like
them to be.

The function vector::push_back, add elements to the end of the
vector.

mrnutty 761 Senior Poster

Don't use OpenGL
All best actual games use DirectX (FarCry, etc..)
Download DirectX SDK and see the tons of samples inside

Could you give a reasonable reason on why not to use openGL.
openGL is capable of achieving almost everything that directX can do.

mrnutty 761 Senior Poster

I don't get it. What eludes people to think that we will use up our
time to write a code for someone else without no compensation
or without no effort on the other party. I am completely baffled by
this type of attitude.

mrnutty 761 Senior Poster

I am a little confused about your question. What are you trying to
do again?

mrnutty 761 Senior Poster

Thanks for option! I'm playing with your code, but I have several errors.
I put counter: int cntr[256] = {0}; in main, and
while(MyFile.get( c ) ) { c = ++c % 256; cntr[c] += 1; } after first while. May be I did mistake, but still in Ask about help!
And, one more question, why you put 256 in array, I think it shoul be 128, isn't it?
If you can , make little bit clear! Thank you!

Its 256 because there are 256 different (narrow) characters, then it
repeats again.

your code should look something like this :

//include libraries 
//using declarative 

int main()
{
   std::ifstream iFile("someFile.txt");
   char c;
   int cntr[256] = {0};
   while( iFile.get(c))
   {
         cout<<c;

             //this is called a circular loop. making sure c is 
             //not above 256 otherwise the array would go 
             //out of bounds.

          c = ++c % 256; 

         cntr[c] +=1;
    }

  return 0;
}
mrnutty 761 Senior Poster

Presumably, using non-temp value is faster.

Think of whats going on.

using temp :

1) Get the value from the user.
2) Copy that value to the address of temp.
3) Search for the value that resides in temp address
4) Copy that value and put it in the address of the array

without using temp :
1) Get value from user.
2) Copy value and place it inside of array address.

mrnutty 761 Senior Poster

Lets see.

Lets just take everything in this code to be related to heap_sort.

for(i= 32; i>1; i--)
   	{
   		SortHeap(arr, i - 1);
	}

I substituted 32 for arr_num_items

This is so far 31 iterations. Inside it, Lets see what sortHeap is.

for(o=root;o>=0;o--)
	{
           //removed
		for(i=root;i>=0;i--)
		{//removed
		}
	}

Where root starts from 15,14,13...0
Take 30 for instance. Inside heapSort there is 15 * 15 iterations
Take 29 for instance. Inside heapSort there is 14* 14iterations
//and so on

31 * 15 * 15 iterations. For the first time.
30 * 14 * 14 iterations. For the seconds time
29 * 13 * 13 iterations. For the third time
n-1 * (n-1)/2* (n-1)/2 iterations, where in this case n starts from 32 to 1

this leads to
31! * 15! * 15 ! = REALLY big number of iterations.

mrnutty 761 Senior Poster

u can also upgrade ur self to DIRECTX programming

"upgrade" might not be the correct choice of words.

mrnutty 761 Senior Poster

Go with the more low level and very capable openGL.

mrnutty 761 Senior Poster

This should be easy.

int cntr[256] = {0}: //counter for each character

//read in char.
//increment cntr for whatever you have read in
while(iFile.get( c ) ) {  c = ++c % 256; cntr[c] += 1; }

There are still some caution to take, but this should be sufficient.

mrnutty 761 Senior Poster

Its stupid :

#include<iostream>

using std::cout;

int main()
{
   int a = 0;
   cout<<"#include<iostream>\n\nusing\tstd::cout;\n\nint main()\n{\n\tint\ta = 0;\n\n\n\treturn 0;\n}\n\n";

return 0;
}
mrnutty 761 Senior Poster

use stringstream. Convert string to numerics. To avoid all the integer
hassle.

mrnutty 761 Senior Poster

std::sort
std::unique

mrnutty 761 Senior Poster

For ifstream :

ifstream iFile("numbers.txt");
	
	if(!iFile.is_open())
	{
		cout<<"Error opening the file\n";
		return 3;
	}

	iFile.seekg(0,std::ios::end);
	unsigned int size = iFile.tellg();
	if(!size)
		cout<<"Empty File\n";

for ofstream,look at the prev post.

mrnutty 761 Senior Poster

Damn Ancient Dragon beat me to it.

Anyhow here it is :

#include <iostream>
#include<fstream>

using namespace std;

int main()
{
	fstream oFile("numbers.txt");
	
	if(!oFile.is_open())
	{
		cout<<"Error opening the file\n";
		return 3;
	}

	oFile.seekg(0,std::ios::end);

	unsigned int size = oFile.tellg();

	if(!size)
		cout<<"Empty File\n";

	else 
	{
		char c;
		while(oFile.get(c))
			cout<<c;
	}
}
mrnutty 761 Senior Poster

What is the function .get()? Its not declared.

bhn = b1.get();

mrnutty 761 Senior Poster

I don't know about Accelerated C++, because I haven't used it before.
But from what I hear, its good also.

mrnutty 761 Senior Poster

string.erase might be what you are looking for.

mrnutty 761 Senior Poster

Google seive prime. Its easy to implement and its fast.
Here is the basic idea.

0) Fill an array with i = 0 to i < MAX
1) Start with number 2. Any multiple of 2 is not a prime so set all numbers multiple of 2 to 0 in the array.
2) Look at the next number non-zero number. Which should be 3.
any multiple of 3 is not a prime, so set it to 0.
3) Look at the next non 0 number, which will be 5. Any multiple of
5 is not a prime, so set any multiple of it to 0 in the array.

4) repeat until i < MAX is false;

mrnutty 761 Senior Poster

Forget about that book. Read a more comprehensive book.
I would suggest C++ Primer plus 5th edition. Its a little over 1000
pages long, all about C++ and its beautiful wonders.

mrnutty 761 Senior Poster

I tried sooo hard to become a physic and see your source code, but
no luck. Maybe it would be easier if you posted the code.

mrnutty 761 Senior Poster

There is a std::sort, and std::unique function. That should solve your
problem. std::sort -- sorts data, std::unique -- removes duplicates
from a sorted data.

mrnutty 761 Senior Poster

int marks[MAX_STUDENTS][MAX_SUBJECTS]={0};
What does this array do? Isn;t this array means that the output of int marks[MAX_STUDENTS][MAX_SUBJECTS] is 0?

It initializes all elements in that array to 0

2:

If I am not mistaken, we are required to put a return; or return (something); at the end of the lines in or the return the data in the function back to int main() function?

But I am curious about how come the program still eun even though you didn't place the return; to it?

e.g
void getInput(int array[MAX_STUDENTS][MAX_SUBJECTS]) /*<--In this function's implemention*/

I think you don't know what a void function is. It tells the compiler
that a this void functions does not return anything back to the
place it was called at.

mrnutty 761 Senior Poster

Here is an idea, Make a program with one of the language you
choose,make a scenario where a random number is generated for
about 100,000 times, each random number generated represents a
language you should learn in depth with. See which has the most
hit, and viola. You got your language.


One a more serious note, just pick one. By the time you decide on a
language, you could have already been learning that language.

mrnutty 761 Senior Poster

For your question # 2, you can use the public interface of the elevator,
but it should be only allowed to be used by passenger, and not the
building class.

And I am not sure what question # 1 is asking. Care to elaborate.

mrnutty 761 Senior Poster

"void fun() throw();"

That declaration tells compiler that this function , fun(), won't throw
any exception.

Similarly :
void fun() throw(myException& m);

Tells compiler and user that this function could throw a exception
shown.

mrnutty 761 Senior Poster
totalArea = (1/2) * PI * (radius*radius);

what you are calculating is the area of a half of a circle.

The area of a circle is pi* r^2

mrnutty 761 Senior Poster

Is it possible to post your complete code, if its not to big?

mrnutty 761 Senior Poster

I think you need to re think your design.

Use for loops instead. Have a function that checks is a number is
prime. Is it returns true then print that number.

for(int i = 0; i < MAX; i++)
    if( isPrime(i) ) cout << i <<" is prime : ";