NathanOliver 429 Veteran Poster Featured Poster

such as char gen_arr[][] ?

NathanOliver 429 Veteran Poster Featured Poster

when you are writing to the file you are using the memblock variable when you should be using sizeof(block) so that write knows how many bites to write to the file.

dst.write(block, sizeof(block));

also on line 15 you are using 4 for the size of test. are you sure that is the size you need? otherwise i would use the same size that you have for block of [memblock + 1].

NathanOliver 429 Veteran Poster Featured Poster

what happens if you move the Ypix deleration to before the for loop like

int Ypix = 0;
for(Ypix; Ypix < image->GetHeight(); Ypix++)
{
//...
NathanOliver 429 Veteran Poster Featured Poster

have you tried making your output stream a fstream like your input stream and using the write() function?

NathanOliver 429 Veteran Poster Featured Poster

well when i add you number together and i dived by 5 I'm getting 8.004. so with your round function you would have ((8.004 * 100) +.5) / 100 = (8.4 + .5) / 100 = 8.9 / 100 = 8.009. with the floor of 8.009 being 8. I'm not sure why you are doing this though. also with double values the last digit can become a one because it is an approximation of the number unlike an int where it is the number.

NathanOliver 429 Veteran Poster Featured Poster

was this the first compile of the program? if it was then you could of just had the errors waiting for you. if not where are the syntax errors? are the related to the doctor or the patient class? if they are can you list them for me

NathanOliver 429 Veteran Poster Featured Poster

what do you mean by after awhile? after awhile in the for loops or after awhile once the program leaves the for loops.

NathanOliver 429 Veteran Poster Featured Poster

at what line in your code the the assertion happen? also is the value for Ypix what you see when the debugger gets to that line? if show it is showing you the value of Ypix before it is assigned to 0.

NathanOliver 429 Veteran Poster Featured Poster

my advice would be to add a member variable to the patient class of type doctor that you assign when you get a doctor. this way you could call the member doctors get fee function.

class Patient
{
public:
// ...
void SetDoctor(Doctor & doc) { doctor = doc; }
// ...
protected:
// ...
Doctor doctor;
};

double Patient::Billing() const
{
return doctor.get_fee_of_doc();
}
NathanOliver 429 Veteran Poster Featured Poster

sorry about the double post i had browser problems.

NathanOliver 429 Veteran Poster Featured Poster

so what is n and where are high and low used for your range checking?

NathanOliver 429 Veteran Poster Featured Poster

well if you want to store questions in a text file where the user can change them the i would suggest just writing a simple output protocol where it is outputted line by line like:

What shape as 4 sides?
1)Triangle
2)Circle
3)Square
3
make this line a blank line
start the next question here

then you could read the file line by line and put your formatting of the string in when you read it from the file. i believe this would very easy for a user to change the questions and answers. hopefully this makes sense.

NathanOliver 429 Veteran Poster Featured Poster

well if you want to store questions in a text file where the user can change them the i would suggest just writing a simple output protocol where it is outputted line by line like:

What shape as 4 sides?
1)Triangle
2)Circle
3)Square
3
make this line a blank line
start the next question here

then you could read the file line by line and put your formatting of the string in when you read it from the file. i believe this would very easy for a user to change the questions and answers. hopefully this makes sense.

NathanOliver 429 Veteran Poster Featured Poster

well the values s, cutoff and p are are not being declared. secondly what is the function rng()? also where are you using high and low?

NathanOliver 429 Veteran Poster Featured Poster

excelent post harry010. tarekwehbe another note for you is that constructor is taking in 2 char arrays and one int. i would the char arrays are the name of the item and something else and that the int is the price of the item so adding to sale_items objects really doesn't make sense unless you just want to add the prices of the objects. if that is the case then i would suggest having an array of sale_item objects of what items the user has selected and and int for the total price of all those objects.

NathanOliver 429 Veteran Poster Featured Poster

well it really depends on how you want 2 sale items to be added together. the function declaration you have looks good though. btw please use code tags.

NathanOliver 429 Veteran Poster Featured Poster

could you please re post the code you have now.

NathanOliver 429 Veteran Poster Featured Poster

you can use the same methods as above you just need to use the right include files and settings. first make a new win 32 console application and check the box for an empty project. add a new cpp file and include stdio.h like #include <stdio.h> . this will let you use the sprintf function.

NathanOliver 429 Veteran Poster Featured Poster

but he will need one for class ClassB because it has an array of ClassA objects

NathanOliver 429 Veteran Poster Featured Poster

the reason you would want to make your own is that with c++ the default will make an exact copy of the class and you will have two classes that point to the same memory address's. now if you delete the pointer in one class then the other class will be pointing to memory that you have no idea what could be in it. with variables that are not on the free store it doesn't matter really except for good programing practices but with free store information it is really a must.

NathanOliver 429 Veteran Poster Featured Poster

the problem with your averages is that you are using i instead of j in

for(int i = 0; i < row; i++)
{
     for(int j=0; j < col; j++)
        {
             hsum = (hsum + (temp[0][i])); <--  USING i SHOULD BE j
        }
}

if you change i to j on this line in both your AverageHigh() and AverageLow() functions it should work fine. as a thought though you really don't need to loops here it could easily be written as

//...
for (int i = 0; i < col; i++)
{
       hsum = (hsum + temp[0][i]);
}
avgh = hsum / col; // or 12 whatever you prefer
//...

as a note i used the variable col here to tell the loop how many times to run and also for the division. this is a more preferred way to program because if you want to change col to some other number i.e. 20 you would have to change the constants in your program that are 12 to 20 otherwise you will have another bug to fix.

NathanOliver 429 Veteran Poster Featured Poster

well a really easy way to fix this is if you can use 2 one dimensional arrays then store the first column in one array and the other column in the second array

int column1[12], column2[12];
int i = 0;
// open the file
while (!inFile.eof()) // goes
{
infile >> column1[i] >> column2[i];
i++;
}

this will also make finding data int the separate columns a lot easier. the problem you were having with your 2d array was on the line while( inFile >> temp[i][0] >> temp[i][1]) . here you were writing data to places that didn't exist because the array was defined as temp[2][12] but this line was going up to temp[11][0] and temp[1][11]. the later was good but the first one you would want the i variable in the second part of the array like temp[0]. this way you would go up to temp[0][11] and temp [1][11]. i hope this makes sense.

NathanOliver 429 Veteran Poster Featured Poster

i take it you are trying to see if the user entered 150 or 175 as the rate and if they do not then tell them they have a wrong entry and re ask for the room rate a simple way for this would be to do this

int rate // this can be any type
cout << "Please enter the room rate: ";
cin >> rate
if ((rate != 150) || (rate != 175)// this will make sure you only get 150 or 175
{
// loop for the right response
NathanOliver 429 Veteran Poster Featured Poster

um for each is not c++ built in keyword. are you using something else or some type of library?

NathanOliver 429 Veteran Poster Featured Poster

a good way to stay orginixed is to split your classes up into 2 files. a .h file that will for the deleeration of the class and a .cpp file that will hold the definition of the class and then you would include them into your main.cpp file such as:

foo.h

class foo
{
 foo(int)
// ...
};

foo.cpp

#include foo.h

foo::foo(int foo)
{
// ...
}

main.cpp

#include "foo.h"

int main()
{
foo foobar(5);
//...
}

btw the new keyword is use to get a pointer to a new object if you just want to make a shape object but not a pointer the just use Shapes square("square", 0, 0, 10, 10);

NathanOliver 429 Veteran Poster Featured Poster

so you want to output the screen output screen to a file?

NathanOliver 429 Veteran Poster Featured Poster

the prototype for SetEndOfFile is BOOL SetEndOfFile(HANDLE hFile); so you do not need to have BOOL SetEndOfFile(HANDLE hFile); all you need to do is write SetEndOfFile(hFile); and if you want you could assign the return value to a bool variable to check for success or failure ie.

bool isSet;
isSet = SetEndOfFile(hFile);
if (!isSet)
{
// do something..
}
NathanOliver 429 Veteran Poster Featured Poster

hey Shawn what exactly is your signature? sorry for going off topic.

NathanOliver 429 Veteran Poster Featured Poster

i guess someone didn't read the second post in the forum. :P

NathanOliver 429 Veteran Poster Featured Poster

from what i can gather from my msdn you will need to read the file file before you write to it so that the file pointer is at the end and will put any new text after everything in the file. you can use the ReadFile() function to read all the data and move the file pointer to the end. hopefully this will help.

NathanOliver 429 Veteran Poster Featured Poster

its not a problem glad to help.

NathanOliver 429 Veteran Poster Featured Poster

well if your using a microsoft complier the mfc is included im not quite sure about the other compliers though. i havent tried making an mfc program in anything other than microsoft visuall c++ 6.0 but with that complier it is very easy to create a simply visual c++ program using the mfc.

NathanOliver 429 Veteran Poster Featured Poster

pulled this of my msdn maybe it will help you out

Physical Disks and Volumes

You can use the CreateFile function to open a physical disk drive or a volume. The function returns a handle that can be used with the DeviceIoControl function. This enables you to access the disk partition table. However, it is potentially dangerous to do so, because an incorrect write to a disk could make its contents inaccessible. The following requirements must be met for such a call to succeed:


The caller must have administrative privileges. For more information, see Running with Special Privileges.
The dwCreationDisposition parameter must have the OPEN_EXISTING flag.
When opening a volume or floppy disk, the dwShareMode parameter must have the FILE_SHARE_WRITE flag.
When opening a physical drive x, the lpFileName string should be the following form: \\.\PHYSICALDRIVE<x>. Hard disk numbers start at 0 (zero). The following table shows some examples of physical drive strings.

String Meaning
\\.\PHYSICALDRIVE0 Opens the first physical drive.
\\.\PHYSICALDRIVE2 Opens the third physical drive.

For an example of opening a physical drive, see Calling DeviceIoControl.

When opening a volume or floppy drive, the lpFileName string should be the following form: \\.\<x>:. Do not use a trailing backslash, which indicates the root directory of a drive. The following table shows some examples of drive strings.

String Meaning
\\.\A: Opens drive A (floppy drive).
\\.\C: Opens drive C (volume).

You can also …

NathanOliver 429 Veteran Poster Featured Poster

the easy way for you to not use the lowest score when you calculate the average is to sort your array to have the lowest score in the first element then use a for loop and start at the element after that. example

int numberOfScores;
float average;
cout << "please enter the number of test scores to enter: ":
cin >> numberOfScores
float * scores = new float[numberOfScorse];
// ask the user for each score
// run the sort and have the lowest score in scores[0]
// then to get the average
for (int i = 1 /*start at 1 because 0 is the lowest*/; 1 < numberOfScores; i++)
{
        average += scores[i];  // this will sum up all the elements except the lowest
}
average /= (numberOfScores - 1); // divide buy the number of scores minus 1 because you dropped the lowest
cout << "The average score is " << average << ".\n";
NathanOliver 429 Veteran Poster Featured Poster

well thank you guys for your help. it is really appreciated.

NathanOliver 429 Veteran Poster Featured Poster

so to avoid problem later on with information in the stream i should either clear the stream after calling cin >> or use strings with cin.getline() .
one other question is will there be a newline in the buffer after running this code?

int a;
cout << "please enter an integer: ";
cin >> a;
NathanOliver 429 Veteran Poster Featured Poster

hi narue i would like to ask if this method should be called after ever cin statement? the reason i ask this is that if i write a program and i have 2 cin >> text; statements then at the end before my return 0; i have to use 2 cin.get(); statements to clear the newlines left in the buffer. i was thinking of trying a loop to eat everything but i don't know if that would cause problems.

char ch;
while (!std::cin.eof())
{
        cin.get(ch);
}
NathanOliver 429 Veteran Poster Featured Poster

i would make sure that time1.h is in a directory where the compiler looks for the files to include. the compiler might not be finding the include file. I've had this problem with msvc 6.0 but I've never used g++

NathanOliver 429 Veteran Poster Featured Poster

as ancient dragon said you need 2 char[]'s. one for the fully assembled file name and one for the user supplied file name.

char filename[30];  // used for the total filename
char FileName[20];  // used to get the filename from the user
int a,b,c;
cout << "please enter the filename: ";
cin >> FileName;
sprintf(filename /*full filename*/, "%s%d.%d.%d.%d%s" , FileName /* user supplied filename*/, counter, A, B, C, ".txt");
// the final ".txt" will make the document a text  document.

maybe this will clear it up for you.

NathanOliver 429 Veteran Poster Featured Poster

alright so you have no code to demonstrate that you have tried recursion or iteration. the iteration is the simple and the fast way of doing this. the logic with a for loop is to ask the user number they want to get and then loop up to it. so if the user entered 6 you would have a for loop like for(int i = 0; i < 4; i++) the reason you only need to go to 4 is beacuse the first to terms of the sequence are both 1. so in the loop you would have a first variable and second variable and both would be 1. then for each iteration of the loop you would assign the second variable to a temp then add the first and second variables together and store that as second and then set first to temp.

// before the loop
int first, second, temp;

// inside the loop
temp = second;
second += first;
first = temp;

this should set you on your way with the iteration. the recursion is a little more difficult and can be very time consuming. for recursion you write a function and pass in what fib number you want and then if it is 1 or 2 you would return 1 otherwise you you would return fib(n-2) + fib(n-1). the logic is to start at the top and then constantly work down to <3. so calling fib(6) would call fib(4) and fib(5) and each one of …

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

never mind i had a typo on line 9 and was ouputting the name twice. got it figured out thanks much guys.

NathanOliver 429 Veteran Poster Featured Poster

well i modified the code hat you had posted and I'm running into a little problem. since i am outputting two strings into the file i am writing the size of the name and then the name and then the size of the password and he password but when i run the code it pulls the name twice. I'm guessing that read does not move the input string to the end of where i pulled from and i need to move it forward somehow but I'm not sure how to do that. my code is as follows

// for writing the data
size_t WriteUser(User &user, ofstream &fout)
{
	size_t uName = user.GetName().capacity() + 1;
	size_t uPass = user.GetPassword().capacity() + 1;
	fout.write(reinterpret_cast<char*>(&uName), sizeof(uName));
	fout.write(user.GetName().c_str(), uName);
	fout.write(reinterpret_cast<char *>(&uPass), sizeof(uPass));
	fout.write(user.GetName().c_str(), uPass);
	return (uName + uPass);
}
// and for reading the data
size_t ReadUser(User &user, ifstream &fin)
{
	size_t uName = 0;
	size_t uPass = 0;
	string filename, filepass;
	fin.read(reinterpret_cast<char *>(&uName), sizeof(uName));
	char * name = new char[uName];
	fin.read(name, uName);
	fin.read(reinterpret_cast<char *>(&uPass), sizeof(uPass));
	char * pass = new char[uPass];
	fin.read(pass, uPass);
	filename = name;
	filepass = pass;
	user.SetName(filename);
	user.SetPassword(filepass);
	delete [] name;
	delete [] pass;
	return (uName + uPass);
}
NathanOliver 429 Veteran Poster Featured Poster

siddhant3s just to be clear what you are doing is outputting the size of the string in binary and then outputting the string. this way you read the size and then are able to pass that into the sizeof() operator for grabbing the string so you ensure that you have the full string. this makes perfect sense but i wasn't sure if it could be done this way. thank you very much

NathanOliver 429 Veteran Poster Featured Poster

Hi all. i am writing a simple log in program and i would like to have a class for users that stores the user name and the password as strings. after i have a user created i would like to output the class with the ios::binary flag set and store them in a file user.dat. in know i can the following code to store the class.

User temp("nathan", "password");
ofstream fout("user.dat", ios::binary);
fout.write((char*) &temp, sizeof(temp));
fout.close();

my main concern though is how would i get it back. I'm not sure what i should use for the sizeof() operator when i read from the file.

User temp;
ifstream fin("user.dat", ios::binary);
fin.read((char*) &temp, sizeof( ? ));
fin.close();

any help would be greatly appreciated.

NathanOliver 429 Veteran Poster Featured Poster

for your loop you should be using while(numRecords < 20) that will fix running the array out of bounds. as Tom Gunn stated about iTemp and iNew they are being assigned a number to the fstream object on the value you got from the file.

NathanOliver 429 Veteran Poster Featured Poster

you char* leftOp is not a MyString object so you cant use leftOp.stringstorage. to use the string just use leftOp

strcat(leftOp, this->stringstorage);
NathanOliver 429 Veteran Poster Featured Poster

the problem i see is that your treating the char as it was a MyString. for chars you can do this.

MyString& MyString::operator=(const char* rightOp)
{
 delete []stringstorage;
 stringstorage = new char[sizeof(rightOp)]
 *stringstorage = *rightOp
 return *this
}

i removed the first const because with assignment you have to change the object and so it shouldn't be const. this is also the same for the addition operator because adding is not const.

as for the error you are having with the addition operator you cannot use strcat() for members of your class. as your compiler says strcat need a char* for each term. also when you use strcat(rightOp, rightOp); you are just concating the string to itself if you want to add one string to another you can do

// decleration
MyString operator+(const MyString& rightOp);
//definition
MyString operator+(const MyString & rightOp)
{
 strcat(this->stringstorage, rightOp.stringstorage);
 return *this;
}

hope this will help you out some

NathanOliver 429 Veteran Poster Featured Poster

u r talking about four million,thats completly out of range for an int declaration...........whether u take long int it will not work,becouse
long int don't have that much range in 32 bit processor..........
but it might work in 64 bit
u may try

the max of a 32 bit unsigned int is 4294967296 or 2147483648 for signed which is more than he needs. the formatting issue is the only problem.

NathanOliver 429 Veteran Poster Featured Poster

from what i can gander i believe that you need to have 1 two dimensional array. judging by the second quote the array should proboly have a size of 10*10 and you can either use 10 for the max or ask the user to input a number less than 10. the first dimension of the array will be 1 through the number entered by user. so if the user enters 6 the first dimension will have 1,2,3,4,5,6. the second dimension will hold the result of multiplying the value of the first dimension by all the values in the first dimension. so in this example will call the array numbers and it will be defined as int numbers[10][10]; . then you would ask the use for the number they would like the table to go up to. if it is less than zero or greater than ten then you need to issue an error and ask for a new number or use a default of 10. if the user enters 6 then you need and algorithm that will make the first dimension be 1-6 and the second dimension will hold the result of multiplying the first dimension by 1-6. maybe this will make things clearer.