i noticed on line 17 you a creating a new SYM object. have you tried using the new keyword?
SYM * temp = new SYM[N]; // using the size you passed into the function for the array
i noticed on line 17 you a creating a new SYM object. have you tried using the new keyword?
SYM * temp = new SYM[N]; // using the size you passed into the function for the array
a way you can do this would be to have a void check function inside a while loop in your main function.
void CheckInput(char[80], bool*);
int main()
{
char[80] cake;
bool good = false;
while (!good)
{
cout << "please enter a cake: "
cin >> cake;
CheckInput(cake, &good);
}
//...
}
void CkeckInput(char[80] cake, bool* good)
{
// run a switch checking cake agiants the valid choices
// if the check succeds then set good to true otherwies do nothing
}
im not sure if you are using pointers though so if you are not this solution wont work.
where are you setting the emp in the node. i see this block for file input
while (fin >> number)
{
head = new LISTNODE(emp , head);
}
but with this you are not doing anything. first you need pull the information into your employee struct and then add it to you list.
what exactly is you error?
also in the first program there is no memory leak.
sorry but your post doesnt make sense. if we use 2/5 - 1/2 with your formula we get:
numerator = (2 * 2) - (1 * 5) = 4 - 5 = -1
denominator = (2 * 5) = 10
so your fraction should be -1/10. not sure why you are not getting it unless it has something to do with your simplify function
the size you want for the substring should be 13 not 14. that should help
yes it is. in order to do the comparison you need to tell the code what character to check. like:
for (int i = 0; i < somestring.length; i++
{
if (somestring[i] == '"')
{
//...
}
}
what string are you using? std::string or something else?
well if you want to check for a " in a string then you can write.
if (somestring[n] == ' " ') // i put a space between the single quotes and the double quote so you could see it. in your program just put '"'.
{
//...
i had a similar problem writing a string to a file and i got some good advice.
well im not sure what is going on. i wrote a simple test program and ran it and it works fine for me. this is what i did.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char * gen_arr[] = {
"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge",
"Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B",
"Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska",
"Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient",
"Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical",
"Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel",
"Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative",
"Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic",
"Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk",
"Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta"};
char country[30];
cout << "enter the word Coutnry: ";
cin.getline(country, 30);
if (_stricmp(country, gen_arr[2]) == 0)
cout << gen_arr[2];
cin.get();
return 0;
}
alright sorry total brain fart. char * gen_arr[];
is right. i did a simple test on my machine where i made a variable char * country = "Country";
and the used country and gen_arr[2] in the _stricmp funtion and it was fine. im wondering how you are getting the value of value. is it a char array or a string as in std::string
?
that definition doesn't work to make a 2d char array. if you want a 2d char array you could say char * gen_arr[2][7] = {"String1","String2"}
such as char gen_arr[][]
?
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].
have you tried making your output stream a fstream like your input stream and using the write() function?
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();
}
but he will need one for class ClassB because it has an array of ClassA objects
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.
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.
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
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..
}
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.
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";
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++
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.
well a multidimensional array has a max that is equal to the max of each dimension multiplied together. so if your array is array[10][5][20] then you would do 10*5*20 to get the max which would be 10000. this works no matter how many dimensions you have. so in your program you would set maxN to the max of each dimension in your array times each other.
when you use << it looks for a method to ouput the data. since you are trying to output the class the compiler looks for a method to ouput but since yo dont have one you are getting this error. you need to overload the << operator so it displays the data of the class.
// class functions declerations
friend ostream & operator <<(ostream & out, IntArray & array);
// more class functions
//...
//class definitions
ostream & IntArray::operator <<(ostream & out, IntArray & array)
{
for (int i = 0; i < numElements; i++)
{
cout << data[numElements] << "\n";
}
return out;
}
not only will this ouput the data of the class but since it returns an ostream reference you can write statements like cout << a << endl << b << endl << c << endl;
otherwise you would have to output each class one at a time
it might be windows specific but I'm not sure. i am using Microsoft visual c++ 6.0 professional and found it in my msdn one day when trying to find an answer to this specific problem for use with a very basic login screen and it didn't care about case sensitivity in the passwords and user names. all of the code that i have made so far has been on windows machines so i couldn't tell you if it is portable to other OS's. i have include my string.h file so that you can see the function prototype. the function is marked with a comment for you.
/***
*string.h - declarations for string manipulation functions
*
* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* This file contains the function declarations for the string
* manipulation functions.
* [ANSI/System V]
*
* [Public]
*
****/
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef _INC_STRING
#define _INC_STRING
#if !defined(_WIN32) && !defined(_MAC)
#error ERROR: Only Mac or Win32 targets supported!
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Define _CRTIMP */
#ifndef _CRTIMP
#ifdef _DLL
#define _CRTIMP __declspec(dllimport)
#else /* ndef _DLL */
#define _CRTIMP
#endif /* _DLL */
#endif /* _CRTIMP */
/* Define __cdecl for non-Microsoft compilers */
#if ( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
#endif
/* Define _CRTAPI1 (for compatibility with the NT SDK) */
#ifndef _CRTAPI1
#if _MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif
#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif
#ifndef _MAC
#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
#endif /* ndef _MAC */
#ifndef _NLSCMP_DEFINED
#define _NLSCMPERROR 2147483647 /* currently == INT_MAX */
#define _NLSCMP_DEFINED
#endif
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
/* Function prototypes */
#ifdef _M_MRX000
_CRTIMP void * __cdecl memcpy(void *, const void *, size_t);
_CRTIMP int __cdecl memcmp(const void *, const void *, size_t);
_CRTIMP void * __cdecl memset(void *, int, size_t);
_CRTIMP char * __cdecl _strset(char *, int);
_CRTIMP char * __cdecl strcpy(char *, const char *);
_CRTIMP char * __cdecl strcat(char *, const char *);
_CRTIMP int __cdecl strcmp(const char *, const char *);
_CRTIMP size_t __cdecl strlen(const char *);
#else
void * __cdecl memcpy(void *, const void *, size_t);
int __cdecl memcmp(const void *, const void *, size_t);
void * __cdecl memset(void *, int, size_t);
char * __cdecl _strset(char *, int);
char * __cdecl strcpy(char *, const char *);
char * __cdecl strcat(char *, const char *);
int __cdecl strcmp(const char *, const char *);
size_t __cdecl strlen(const char *);
#endif
_CRTIMP void * __cdecl _memccpy(void *, const void *, int, unsigned int);
_CRTIMP void * __cdecl memchr(const void *, int, size_t);
_CRTIMP int __cdecl _memicmp(const void *, const void *, unsigned int);
#ifdef _M_ALPHA
/* memmove is available as an intrinsic in the Alpha compiler */
void * __cdecl memmove(void *, const void *, size_t);
#else
_CRTIMP void * __cdecl memmove(void *, const void *, size_t);
#endif
_CRTIMP char * __cdecl strchr(const char *, int);
_CRTIMP int __cdecl _strcmpi(const char *, const char *);
_CRTIMP int __cdecl _stricmp(const char *, const char *); ///////// here is the function //////////////////////////
_CRTIMP int __cdecl strcoll(const char *, const char *);
_CRTIMP int __cdecl _stricoll(const char *, const char *);
_CRTIMP int __cdecl _strncoll(const char *, const char *, size_t);
_CRTIMP int __cdecl _strnicoll(const char *, const char *, size_t);
_CRTIMP size_t __cdecl strcspn(const char *, const char *);
_CRTIMP char * __cdecl _strdup(const char *);
_CRTIMP char * __cdecl _strerror(const char *);
_CRTIMP char * __cdecl strerror(int);
_CRTIMP char * __cdecl _strlwr(char *);
_CRTIMP char * __cdecl strncat(char *, const char *, size_t);
_CRTIMP int __cdecl strncmp(const char *, const char *, size_t);
_CRTIMP int __cdecl _strnicmp(const char *, const char *, size_t);
_CRTIMP char * __cdecl strncpy(char *, const char *, size_t);
_CRTIMP char * __cdecl _strnset(char *, int, size_t);
_CRTIMP char * __cdecl strpbrk(const char *, const char *);
_CRTIMP char * __cdecl strrchr(const char *, int);
_CRTIMP char * __cdecl _strrev(char *);
_CRTIMP size_t __cdecl strspn(const char *, const char *);
_CRTIMP char * __cdecl strstr(const char *, const char *);
_CRTIMP char * __cdecl strtok(char *, const char *);
_CRTIMP char * __cdecl _strupr(char *);
_CRTIMP size_t __cdecl strxfrm (char *, const char *, size_t);
#ifdef _MAC
unsigned char * __cdecl _c2pstr(char *);
char * __cdecl _p2cstr(unsigned char *);
#if !__STDC__
__inline unsigned char * __cdecl c2pstr(char *sz) { return _c2pstr(sz);};
__inline char * __cdecl p2cstr(unsigned char *sz) { return _p2cstr(sz);};
#endif
#endif
#if !__STDC__
/* prototypes for oldnames.lib functions */
_CRTIMP void * __cdecl memccpy(void *, const void *, int, unsigned int);
_CRTIMP int __cdecl memicmp(const void *, const void *, unsigned int);
_CRTIMP int __cdecl strcmpi(const char *, const char *);
_CRTIMP int __cdecl stricmp(const char *, const char *);
_CRTIMP char * __cdecl strdup(const char *);
_CRTIMP char * __cdecl strlwr(char *);
_CRTIMP int __cdecl strnicmp(const char *, const char *, size_t);
_CRTIMP char * __cdecl strnset(char *, int, size_t);
_CRTIMP char * __cdecl strrev(char *);
char * __cdecl strset(char *, int);
_CRTIMP char * __cdecl strupr(char *);
#endif /* !__STDC__ */
#ifndef _MAC
#ifndef _WSTRING_DEFINED
/* wide function prototypes, also declared in wchar.h */
_CRTIMP wchar_t * __cdecl wcscat(wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl wcschr(const wchar_t *, wchar_t);
_CRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl wcscpy(wchar_t *, const wchar_t *);
_CRTIMP size_t __cdecl wcscspn(const wchar_t *, const wchar_t *);
_CRTIMP size_t __cdecl wcslen(const wchar_t *);
_CRTIMP wchar_t * __cdecl wcsncat(wchar_t *, const wchar_t *, size_t);
_CRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t);
_CRTIMP wchar_t * __cdecl wcsncpy(wchar_t *, const wchar_t *, size_t);
_CRTIMP wchar_t * __cdecl wcspbrk(const wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl wcsrchr(const wchar_t *, wchar_t);
_CRTIMP size_t __cdecl wcsspn(const wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl wcsstr(const wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl wcstok(wchar_t *, const wchar_t *);
_CRTIMP wchar_t * __cdecl _wcsdup(const wchar_t *);
_CRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *);
_CRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t);
_CRTIMP wchar_t * __cdecl _wcsnset(wchar_t *, wchar_t, size_t);
_CRTIMP wchar_t * __cdecl _wcsrev(wchar_t *);
_CRTIMP wchar_t * __cdecl _wcsset(wchar_t *, wchar_t);
_CRTIMP wchar_t * __cdecl _wcslwr(wchar_t *);
_CRTIMP wchar_t * __cdecl _wcsupr(wchar_t *);
_CRTIMP size_t __cdecl wcsxfrm(wchar_t *, const wchar_t *, size_t);
_CRTIMP int __cdecl wcscoll(const wchar_t *, const wchar_t *);
_CRTIMP int __cdecl _wcsicoll(const wchar_t *, const wchar_t *);
_CRTIMP int __cdecl _wcsncoll(const wchar_t *, const wchar_t *, size_t);
_CRTIMP int __cdecl _wcsnicoll(const wchar_t *, const wchar_t *, size_t);
#if !__STDC__
/* old names */
#define wcswcs wcsstr
/* prototypes for oldnames.lib functions */
_CRTIMP wchar_t * __cdecl wcsdup(const wchar_t *);
_CRTIMP int __cdecl wcsicmp(const wchar_t *, const wchar_t *);
_CRTIMP int __cdecl wcsnicmp(const wchar_t *, const wchar_t *, size_t);
_CRTIMP wchar_t * __cdecl wcsnset(wchar_t *, wchar_t, size_t);
_CRTIMP wchar_t * __cdecl wcsrev(wchar_t *);
_CRTIMP wchar_t * __cdecl wcsset(wchar_t *, wchar_t);
_CRTIMP wchar_t * __cdecl wcslwr(wchar_t *);
_CRTIMP wchar_t * __cdecl wcsupr(wchar_t *);
_CRTIMP int __cdecl wcsicoll(const wchar_t *, const wchar_t *);
#endif /* !__STDC__ */
#define _WSTRING_DEFINED
#endif
#endif /* ndef _MAC */
#ifdef __cplusplus
}
#endif
#endif /* _INC_STRING */
there is a function in the <string> header file called _stricmp that will convert all the characters to there lowercase. the function is defined as
int _stricmp( const char *string1, const char *string2 );
this function will return 0 if the strings are equal. less than 0 and greater than zero returns mean they do not match. to use this i would write
#include <string>
#include <iostream>
using namespace std;
int main()
{
string string1 = "abcd";
string string2 = "ABCD";
int equal;
equal = _stricmp(string1.c_str(), string2.c_str());
// using the c_str function here to pass the char array to the
//function because it does not take in a string but a char
if (equal == 0)
cout << "the strings are equal"
else
cout << "the strings are not equal"
return 0;
}
hope this helps you out
have you tried adding a cout statement before you assign the value to the array to make sure you are getting an assignment.
f_in.read((char *)&speech, 2);
cout << value[i] << "\t"; // show the value before assignment
value[i] = speech;
cout << value[i] << std::endl;
f_out.write((char *)&speech, 2);
are you getting the same number for every value?
are you sure that the size of each element is 2?
sorry i meant to do this
char ch;
ifstream fin(*infile);while (!fin.eof()){for (int count=0; count < 4; count++) { for (i = 0; i < SIZE - 1; i++){fin >> inchar//...ifstream fin(*infile);
while (!fin.eof())
{
for (int count=0; count < 4; count++)
{
for (i = 0; i < SIZE - 1; i++)
{
fin.get(ch);
//...
I'm pretty sure that will work.
well I'm not to sure about FILE but i know that if you do this you can loop through the file until the end.
ifstream fin(*infile);
while (!fin.eof())
{
for (int count=0; count < 4; count++)
{
for (i = 0; i < SIZE - 1; i++)
{
fin >> inchar
//...
on line 47 you have
temp.estimatedTime = h.estimatedTime + h.estimatedTime;
all this is doing is adding the term h.estimatedTime
to itself effectively doubling it. if you want to add the first and second terms you can do
temp.estimatedTime = this->estimatedTime + h.estimatedTime;
this will add both terms together if the data is public. if you want to keep the data private i would suggest writing some accessor functions like int GetEstimatedTime() {return estimatedTime }
so you can get the private data.
if you mean that you want to round the number to a specific number of decimal places you might want to make a char array and use _gcvt() to store in the number of digits you want. for your example if you want pi to 5 places you could do this.
const double fullPi=3.141592653589793;
char * pi = new char[8];
_gcvt(fullPi, 8, pi);
_gcvt() takes in a double and outputs the number of digits specified in the second term then it outputs the string into the char[] in the third term. for this you need to have an array that is big enough to hold the digits before the decimal place the decimal itself the number of digits after the decimal point and the terminating null at the end so in this case for 5 places you need a char[] of size 8.
for this part of code
char * pChar[255];
pChar = new char[255];
you do not want to declare pchar with its elements. you save that for the new operator part. so you would want to do this
char * pChar;
pChar = new char[255];
also when you delete an array you always want to place the array operator before the name of the array. otherwise you will just delete the head of the array but the rest of it will still be sitting there in memory taking up resources until your application exits.
make sure you alway use delete [] variable_name;
also it is always a good idea to set your pointer to null after deleting it. deleting a pointer that has already been deleted is guaranteed to crash your system but deleting a null pointer is safe.
in your void viewAllInfo(Person year1[], int size)
you are getting a redefintion error delete your decleration of i from this line. int m1, m2, m3, m4, i = 0;
to get this int m1, m2, m3, m4;
also in my compiler i hade to include the string header file #include<string>
to make the cout statements dealing with strings to output
well when i run the simulation it displays hex numbers for awhile and then it will show me 2 sets of hex numbers and then ask me to press enter to continue and every time i do it just does it again. not quite sure whats going on yet but ill get back to you tomorrow afternoon/evening with anything that i find.
well now you have another beast to deal with. the best of luck getting it running.
would you mind terribly much if you messaged me with the code attached so i could try something?
alright. what is going on here i believe is that begin.sim[sim].field[x][y].rabbits
is giving you a pointer of a pointer so to get down to the original pointer try *begin.sim[sim].field[x][y].rabbits
i hope that this will work
Thank you. okay to make sure you want pointer to hold the rabbit object right?
could you please post the declaration of "pointer"
well you could do this
ofstream fout("TheOneFile.txt", ios::app);
fout << something;
fout.close();
this way everytime you need to ouput something into the file you open it, store the information, then close the file. this way you can have every file of source code store information into the file without having to worry that another peice of code has access to that file. to be double sure always include this before trying to store to a file
if (!fout)
errorCondition = true;
you really can do anything if the oppening fails i just put this in as an example.
If you want the address of the pointer you would want to say
pointer = &begin.sim[sim].field[x][y].rabbits;
that will give you the address of the pointer not the address that the pointer holds. hope thats what you wanted
I would cycle through each letter in the string that was inputed an see if it was repeated then you will be down to at most a number of checks equal to the size of the string.