mrnutty 761 Senior Poster

"The user enters: hhmmss "

like this I assume : 074023

which is = 7:40:23

1) check if the 1st and 2nd number is <= 24
2) check if 3rd and 4th number is <= 60
3) check if 5th and 6th number is <= 60

if all return true, then output what you need.

mrnutty 761 Senior Poster

Easy way out. Make member func static :

#include <iostream>

using namespace std;

struct temp
{
	static int addition(int x, int y)
	{return (x + y);}

	int operation (int x, int y, int (*functocall)(int,int))
	{
		int g;
		g = (*functocall)(x,y);
		return (g);
	}
};


int main ()
{
  int m;
  
  temp momo;

  m = momo.operation(3, 4, temp::addition);  
  cout << m;

  cin.get();
  return 0;
}
mrnutty 761 Senior Poster

Its because you open your file multiple times without reseting
its position.

Here is your program. I don't know if the output is correct, but it runs:

#include<iostream>
#include<fstream>
#include<cmath>

using namespace std;

double avg_file(ifstream& source_file)
{
	
	double number_in_file;
	double total = 0;
	int count = 0;
	source_file >> number_in_file;
	while (! source_file.eof())
	{
		source_file >> number_in_file;//SWITCHED
		total = number_in_file + total;
		count ++;
	}

	source_file.seekg(0,ios::beg); //NEW -- reset cursor position in file

	//average of numbers in file
	return (total/count);
}

double std_dev (ifstream& in_file, double average)
{
	double number_in_file = 0;
	double std_dev_f;
	double sum_diff = 0;
	int count = 0;

	while (! in_file.eof())
	{
		in_file >> number_in_file; //ADDED
		sum_diff = pow((average-number_in_file),2)+ sum_diff;
		count++;
	}
	std_dev_f =sqrt(sum_diff/count); 
	return (std_dev_f);
}
int main()
{
	ifstream fin;
	//ofstream fout;
	fin.open("numbers.txt");
	if (fin.fail())
	{
		cout << "erorr on opening the file \n";
		exit (1);
	}
	cout << "the calculated average is  " << avg_file(fin) << endl;	

	cout << "the std devitation is     "  << std_dev(fin,avg_file(fin)) << endl;
}
mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

here if you want to make the changes without breaking the code
now , make that x y and z mutable.

dirty but it will help you not to break the code.

why would you suggest that? Your just suggesting bad practice.

mrnutty 761 Senior Poster

what kind of project?

mrnutty 761 Senior Poster

How well do you know c++?

for loops, do while, if else, class, ...?

Also there is practice problem here.

tux4life commented: Indeed :) +19
mrnutty 761 Senior Poster

usually :

std::ostream& operator <<(std::ostream& ostrm)
{
    ostrm << "Hello its overloaded\n";
   return ostrm;
}
std::istream& operator >>(std::istream& istrm)
{
   cout<<"Enter a number  :  ";
   istrm >> MyClass::myNumber;

    return istrm;
}

note overloading the << operator should be a friend, so you can use it like this :

cout << myClassVar;

if not then you would use this syntax :

myClassVar <<cout;

which is confusing.

mrnutty 761 Senior Poster
e lambda=5.32*10^-07

You do know that '^' is called XOR and is not "to the power of"
operator ?

10 ^ -07 != 0.0000001;

mrnutty 761 Senior Poster

Do you have to use arrays, or could you use vectors?

Even if you don't know what or how to use vectors, they are quite
easy. And it would be a learning experience.

Vectors are way much better and safer that raw arrays. You can
have any size of vectors. For arrays it has to be declared
like so , int a[40]. For vector they can be any size allowed by
memory.

mrnutty 761 Senior Poster

From OP pdf file :

//Use the following code to check for file error
if (input.fail()){
   cerr<<"File not found!"<<endl;
   system("PAUSE");
return 0
mrnutty 761 Senior Poster

For question # 1

(a) Is allocated with new or (b)just something like int a[1000000];

option a, use delete [].
option b, its destructor is called, and deletes it automatically. But
as Ancient dragon pointed out, there could be stack overflow.

mrnutty 761 Senior Poster

Check if this is somewhat of what your looking for. I use the same
logic as mentioned and suggested before. Its not complete but,
its just to help you out.

void prnt(char Map[][5])
{
	for(int i = 0; i < 5; i++)
	{
		for(int j = 0; j < 5; j++)
		{
			cout<<Map[i][j]<<"  ";
		}
		cout<<endl;
	}

}
void setPos(int x, int y, char Map[][5])
{
	for(int i = 0; i < 5; i++)
	{
		for(int j = 0; j < 5; j++)
		{
			if( i != x || j != y)
				Map[i][j] = '*';
			else Map[i][j] = 'R';
		}
	}
}
int main()
{ 	
	char Map[5][5] = 
	{
		{'*','*','*','*','*'},
		{'*','*','*','*','*'},
		{'*','*','*','*','*'},
		{'*','*','*','*','*'},
		{'*','*','*','*','*'}
	};
	
 
	
	cout<<"Original content \n";
	prnt(Map);

	int R = 0;//starting row of robot
	int C = 0; //starting col of robot

	//destinition row and column
	const int destR = 4;
	const int destC = 4;

	Map[R][C] = 'R';
	Map[destR][destC] = 'D';
	
	cout<<"\n\n'R'obot in place and 'D'estination locked\n\n";
	prnt(Map);


	//update time in milliseconds
	const unsigned int UPDATE_TIME = 1250; //1.25 seconds

	//slope formula : 
	//  (y_2 - y_1)
	//  -----------
	//  (x_2 - x_1)

	float slope = (destR - R) / (float) (destC - C);

	float newR(R),newC(C); //new position

	while( (newR != destR) &&  (newC != destC) )
	{
		static unsigned int clk_strt = clock();
		int clk_end = clock();

		if( (clk_end - clk_strt) > UPDATE_TIME ) //update position only if update time has been reached
		{
			clk_strt = clk_end; //reset time

			newR += slope;
			newC …
mrnutty 761 Senior Poster

Just a wild guess.

CGUIEditBox
C - c language?
GUI - graphical user interface
EditBox - edit box

CGUIFont
C - c language ?
GUI - graphical user interface
Font - font

CXMLWriter
C - c language ?
XML - Extensible Markup Language
Writer - writer

mrnutty 761 Senior Poster

Copied and pasted and the value I got was : 0.0004254 for PD

mrnutty 761 Senior Poster

Google is your friend.

Particularly check the first post. It talks about using MSB to detect
overflow.

mrnutty 761 Senior Poster

Try
::px = ((rect.right - rect.left) / 2) - 60;

I am assuming there is a local variable hiding the global.

mrnutty 761 Senior Poster

What Gui do you use or wan't to use ?

mrnutty 761 Senior Poster
int twodee[5][5];

creates a 5x5 matrix.

To draw a graph you might have to use some sort of GUI

mrnutty 761 Senior Poster

Do you know the conversion formula from Fahrenheit to Celsius?

If so the rest should be formatting issues. Use a loop from i = 20
to i <= 300, and use the conversion formula and display the
corresponding Celsius to a Fahrenheit, or vice versa.

mrnutty 761 Senior Poster

Haven' you tried something? Give some idea you might have on
how to go about this.

mrnutty 761 Senior Poster

I don't know if this was mentioned, but when you have a function
pointer like for example, float (*pF)(float) , you can only pass
it a function that has the same prototype.

For example :

void drawGraph( float (*graphFunc)(float x) , float leftBound, float rightBound, float epsilon )
{ 
  for(leftBound; leftBound < rightBound; leftBound += epsilon)
      { 
           (*graphFunc)(leftBound);
       }
}

And calling it like this :

drawGraph(cos);
drawGraph(sin);

//since cos and sin have an overloaded function float cos(float), and float sin(float), It works, although its not tested.

but if you have your own drawFunction with a prototype for example
like this , float myDraw(char); //draws letters,
and you try to pass it to drawGraph(myDraw); //Then it would
be an error because of non-matching signature.

mrnutty 761 Senior Poster

>Whats up with the attitude?
Remove: the h*ll from that sentence :P

Then it would be grammatically incorrect.

Nick Evan commented: Hehe. +25
mrnutty 761 Senior Poster

Try cout.precision(25);

mrnutty 761 Senior Poster

See if this could help you. It is my string class assignment operator function.

Letters& Letters::operator =(Letters& Str1) //assignment operator
	{
		if(this == &Str1) //check for self assignment
			return *this;

		delete [] str;

		Len = Str1.Len;
		
		str = new char[Len+1];
		
		strcpy(str,Str1.str);
		
		str[Len] = NULL;

		return *this;
	}

I think this should help you somewhat. Also is your vector
class dynamic or is there some sort of limiting number, or
is it a wrapper to std::vector, or is it something your teacher provides and you don't know?

mrnutty 761 Senior Poster

Here is another way you might want to try. Its in c++ though.
You could try to convert it into c.

float GetFloat()
{
	std::cout<<"Enter a number please : ";
	float num(0);
	cin >> num;

	while(!cin)
	{
		cin.clear();
		while(cin.get() != '\n')
			continue;

		cout<<"\nPlease enter a number : ";
		cin >> num;
	}

	return num;
}

use it like this :

int main()
{
    float num = GetFloat();
   return 0;
}
mrnutty 761 Senior Poster

If you print them side by side then it would make a blank diamond
shape in the middle. So instead of creating different shape 1 by one,
try to think about the whole shape as one. In fact, draw it on a piece
of paper, and try to think of some logic.

1) How many spaces does the first row have?
2) What is the rate of increase in spaces and stars?
3) How is it mirrored?

mrnutty 761 Senior Poster

Here is one of my beginning projects last year :

const int row = 1;

	for(int i = 0; i < row; i++)
	{
		for(int j = row-i; j ; j--)
			cout<<" ";
		
		for(int k = i*2; k >= 0; k--)
			cout<<"*";	

		cout<<endl;
	}

	for(int i = row; i >= 0; i--)
	{
		for(int j = i; j < row; j++)
			cout<<" ";
		
		for(int k = i*2; k >= 0; k--)
			cout<<"*";	

		cout<<endl;
	}
mrnutty 761 Senior Poster

here is one that I use sometimes. Note that this does not work for every
bitmap images.

int LoadBitmap( wchar_t* filename)
{
   GLubyte* pixels;
   HBITMAP hbmp;  
   BITMAP bmp; 
   GLuint size;
   GLenum format;
   GLuint totalBytes;

   texID++;

   hbmp=(HBITMAP)LoadImage(GetModuleHandle(NULL), filename, 
                IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION |  
                LR_LOADFROMFILE );

   if(hbmp==NULL)
   {
	   MessageBox(NULL,L"ERROR : CANNOT LOAD FILE!",L"IMAGE LOADING",MB_OK);
	   return -1;
   }

   GetObject(hbmp,sizeof(bmp), &bmp);  				   		 
 
   size = bmp.bmHeight*bmp.bmWidthBytes;
   
   totalBytes = bmp.bmBitsPixel/8;

   switch(bmp.bmBitsPixel)
   {
		case 1:
		case 4: 
		case 8:
			format = GL_LUMINANCE;			
			break;

		case 24:
			format = GL_RGB;
			break;

		case 32:
			format = GL_RGBA;
			break;
   }

   pixels = new GLubyte[size];

   memcpy(pixels,bmp.bmBits,size);

//Now use data. I used this for openGL but deleted that stuff
// because of it not begin relevent.

	

//After doing something with the data delete object.
   DeleteObject(hbmp);   

   delete [] pixels;

   return  true;
}
mrnutty 761 Senior Poster

"Hey firstPerson, where the h*ll do you see in his spec that he has
to use a class?"

That was uncalled for. If he really needs to use structs, then just
switch the keyword class to struct, realizing that struct by default
has public members , while class by default has private.

Whats up with the attitude?

mrnutty 761 Senior Poster

Create a class to hold data's:

class PersonInfo
{
private:
	std::string name;
	std::string nationality;
	char gender;
	// and so on	
public:
	 //some methods to get datas , set datas and any other function
	//that you think will be sufficient to this class usually goes here.

};

Now create a array of class :

const int NUM_OF_SUTDENTS = 25; 
PersonInfo[NUM_OF_SUTDENTS ];
//use loops to initialize datas. 
// and go on from there.
mrnutty 761 Senior Poster
// code intentionally advanced to deter cheaters
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
#include <cmath>

template <typename T>
struct SquareOfDiff:
    public std::binary_function<T, double, T>
{
    T operator()(T x, double mean) const
    {
        x -= (T)mean;
        return x *= x;
    }
};

int main()
{
    std::vector<double> set;
    double mean;

    std::cout << "Distriution set: ";
    std::copy(
        std::istream_iterator<double>(std::cin),
        std::istream_iterator<double>(),
        std::back_inserter(set));

    mean = std::accumulate(set.begin(), set.end(), 0.0) / set.size();
    std::transform(
        set.begin(), set.end(), 
        set.begin(), std::bind2nd(SquareOfDiff<double>(), mean));
    mean = std::accumulate(set.begin(), set.end(), 0.0) / set.size();

    std::cout << "Standard deviation: " << sqrt(mean) << '\n';
}

I get that what you posted is more safe. But how is that code supposed
to help the OP ( a beginner ) understand what he needs, when he most likely,
has no clue of what some of the code does.

@Jake :
This might be of help.
Link

mrnutty 761 Senior Poster

I am not so clear about this part:

the copy constructor takes an int as a parameter and returns a new int with the same value as the value passed in. So for the declaration of 'student' the copy constructor for int is called and passed the integer value 5. So for 'student' a new int is created and given the value 5.
Likewise, for 'subject', the int copy constructor is passed 3, so it returns a new int with the value 3 .

I would like to ask whether if, this means that when the 'student' is being declared, it will follow the int student which says 5 and the 'subject' will follow the int subject called 3.

If by that what you mean is student will become 5 and subject will
become 3 then yes.

And then when the function is being called, the array called 'student' in

int marks[student][subject];

will be equal to 3?

Is it what you mean?

student will be 5 and subject will be 3. Same as int marks[5][3].
student is the row. Subject is the column.

And also I would like to ask

1: how would the system affect the 'student' and 'subject' if the constant is not being placed

It would result as an error. And would not compile

2: In nomral application when we use only one array, do we also need to place constant to prevent such problem?

Whenever you create an array you have to have …

mrnutty 761 Senior Poster


Yet another way (albeit more long winded, but still correct!):

const int student, subject;
student=5;
subject=3;
int marks[student][subject];

So all three of the above snippets of code do exactly the same thing. But the first two are shorter and more succinct!

I don't know about your compiler, but mines dosen't allow
declaration of of const object without being initialized. So the
above code would be an error.

Just for the sake of it, take a look at the errors, and see why
one wrong thing can lead to many errors.

error C2734: 'student' : const object must be initialized if not extern
error C2734: 'subject' : const object must be initialized if not extern
error C3892: 'student' : you cannot assign to a variable that is const
error C3892: 'subject' : you cannot assign to a variable that is const
error C2057: expected constant expression
error C2466:cannot allocate an array of constant size 0
error C2466: cannot allocate an array of constant size 0
error C2087: 'marks' : missing subscript
error C2133: 'marks' : unknown size
JasonHippy commented: Good spot, consider myself rightly corrected! +2
mrnutty 761 Senior Poster

1) Find the slope between the initial coordinate and the final
coordinate.

2) Increase x and y by the slope.

Although there might be some caution you might have to take.

This is basically what I and sky suggested earlier. It might help you to hear it again.

mrnutty 761 Senior Poster

True.
But the program still wouldn't work

Yes thats true. I never said it would work.

mrnutty 761 Senior Poster

I think you can just do the following :

get the user input. Find '?' character. Replace '?' character with
some other letter. Check for valid word. save it to result list.

mrnutty 761 Senior Poster

This is cute.

First of, look at the patterns. Tell me what you can figure.


Its interesting how the patterns unfolds. Just look at the result :

a
b c b 
c d e d c 
d e f g f e d 
e f g h i h g f e 
f g h i j k j i h g f 
g h i j k l m l k j i h g 
h i j k l m n o n m l k j i h 
i j k l m n o p q p o n m l k j i 
j k l m n o p q r s r q p o n m l k j 
k l m n o p q r s t u t s r q p o n m l k 
l m n o p q r s t u v w v u t s r q p o n m l 
m n o p q r s t u v w x y x w v u t s r q p o n m 
n o p q r s t u v w x y z   z y x w v u t s r q p o n 
o p q r s t u v w x y z   z y x w v u t s r q p …
mrnutty 761 Senior Poster

Do you know how to create a pascal triangle without recursive?

If so then doing it recursive won't be that far off. Give it a go and see
what happens.

mrnutty 761 Senior Poster

Its much easier than you are making it.

cin >> limitNum;

for(int i = 0; i < limitNum; i++) 
    cout<<i<<" ";
mrnutty 761 Senior Poster

I tried changing the int to double but then the program will not run"

Thats because of your function. It accepts an int array. You need
to change the function to accept an double array.

void selection_sort(int input_array[], int input_size);
void display_array(int input_array[], int input_size);

to

void selection_sort(double input_array[], int input_size);
void display_array(double input_array[], int input_size);

And also change the function header to match the prototype.

mrnutty 761 Senior Poster

On an alternative note, there is std::sort() function.

mrnutty 761 Senior Poster

It gives me no errors :

#include <iostream>

using namespace std;

void getmarks(int marks[][3]);

int main()
{
   const  int student(5),subject(3);


    int marks[student][subject];
    int i,count;


    //Getting the marks
    getmarks(marks);

    //Displaying the marks
    cout<<"\n\t\t\tSubject 1\tSubject 2\tSubject 3"<<endl;
    for(i=0;i<5;i++)
    {
        cout<<"Marks for student "<< i+1;
        cout<<"\t";
        for(count=0;count<3;count++)
        {
            cout<<"   " << marks[i][count]<<"\t\t";
        }
        cout<<"\n";
    }
    return 0;
}


void getmarks(int marks[][3])
{
    int i,count;
       for(i=0;i<5;i++)
    {
        for(count=0;count<3;count++)
        {
            cout<<"Enter the marks for student: " << i+1;
            cout<<", " <<"subject " << count+1<<": ";
            cin>>marks[i][count];
        }
    }
    return;
}
mrnutty 761 Senior Poster

Use Euclid formula :
Formula(wiki)

mrnutty 761 Senior Poster

Its called Initializer list

mrnutty 761 Senior Poster

i wanna know that if a program consists of 10 lines
n if we compile it , it shows increased no of lines compiled why:icon_question:

Why does it matter. I hope you are not worried about the program
size at 10 lines.

mrnutty 761 Senior Poster

int getmarks(int marks[][3]);

Note : You have to specify the column. Thats why the 3 is there.
Although it could be any number.

mrnutty 761 Senior Poster
cout.setf(std::ios_base::fixed,std::ios_base::floatfield);
int someNumber  = 10;
cout.precision( someNumber );
mrnutty 761 Senior Poster

what do you think?

mrnutty 761 Senior Poster

The difference is re-usability. Imagine creating a program thats
stores tons of information about a person. If you needed to hold
that data for a lot of people. It would save you a lot of time, by using
classes instead of regular variables and functions.