Agni 370 Practically a Master Poster Featured Poster

Can you rephrase your question? i can understand it in parts but its not very clear what you have and what you want to do.

Agni 370 Practically a Master Poster Featured Poster

like i pointed out in the thread below this, where are you assigning anything to 'Applicant item;', ok so you changed it from a pointer to an object but where are the values? the 'app' object you create in main, should be created inside the while loop, then passed by value and assigned to another->item.

Agni 370 Practically a Master Poster Featured Poster

and the errors are?? .....

Agni 370 Practically a Master Poster Featured Poster
for(i = 0 ; *Src!='\0' ; Src++)
    tmp[i]=*Src;

should increment 'i' also. as of now 'i' remains 0 throughout.

Ancient Dragon commented: Good catch :) +36
Agni 370 Practically a Master Poster Featured Poster

OK.. my bad... True .. it will not work.

Agni 370 Practically a Master Poster Featured Poster

>>I did was to Initialize char * string1 = "longer than string2" and evrything else the same and it didnt work either
I didn't work because you can't change string literals, which is what you attempted to do. But you could have done it like this: char string1[] = "longer than string2" , which will put the text in writeable memory.

I thought you could always assign a char* to another char*. Are you sure that declaring

char* string1 = "Bigger than String2";

wont work?

Agni 370 Practically a Master Poster Featured Poster

How do you know its not opening the file? is it printing 'File not found' ?? Why dont you try and read something from the file and confirm?

Agni 370 Practically a Master Poster Featured Poster

if its printing 'Hello.' then it has executed the switch statement..

Agni 370 Practically a Master Poster Featured Poster

I don't see a problem at all. The only reason could be (assuming that the file is very much present in the same directory where you are executing this code) is that you might entering 'h' instead of 'H'. Are you not getting the 'Hello.' on the screen either?

Agni 370 Practically a Master Poster Featured Poster
Agni 370 Practically a Master Poster Featured Poster

i thought it was 'Testnamespaces.h' .. anyways is the path of the file available in your include path? -I option of the compiler? is this file actually present in the path, did you confirm? if you're using some IDE then you might have to check what's the include path set to.

Agni 370 Practically a Master Poster Featured Poster

nope.. i want to know when you get this error, in what file, whats the include statement there or anything else that you think is relevant. obviously i have no clue what you're trying to do unless you tell me..rt? ..

Agni 370 Practically a Master Poster Featured Poster

is this file present in the Test directory? can you post the include statement or the .h file if possible?

Agni 370 Practically a Master Poster Featured Poster

Dont use 'eof' as an exit indicator for the loop. eof() is true only after the end of file is read and not when end of file is reached as a result your getting one extra character. use while(file.getline(<args>)) instead of 'eof'.

Agni 370 Practically a Master Poster Featured Poster

Please use 'Code Tags' for posting code

to your qs. you will need one more loop, something like

for(int row_A=0; row_A<num; row_A++)
{
  for(int row_B=0;row_B<=row_A;row_B++)
  {
      cout << ch;
  }
  cout << "\n";
}
Agni 370 Practically a Master Poster Featured Poster

or you could do something like ...

int* arr = new int[rows * cols];

then go on adding elements to it ...

Agni 370 Practically a Master Poster Featured Poster

Why dont you just compile and test it?

Agni 370 Practically a Master Poster Featured Poster

and you need a default constructor of the class too, since you have declared your own ctor the compiler will not generate it for you...

Agni 370 Practically a Master Poster Featured Poster
fstream openfile;
openfile("my_file.txt");
if(openfile.fail())
{
      cout<<"Error opening file.";
}
else
{
      mainprog();
}

i'm surprised that this doesn't give you a compilation error. when i compile it i get a straight forward error

fileopenDan.cpp(9) : error C2064: term does not evaluate to a function

and the both the forms work well if you say

openfile.open("my_file.txt", fstream::in|fstream::out|fstream::app);
Agni 370 Practically a Master Poster Featured Poster

yah i want to open a file file1.dat write content into it ..close and oen a new file with a name file2.dat write content n close it .. and continue this !!

I assumed you needed multiple files open at the same time, for above requirement AD has already given you the code. Go through it.

Agni 370 Practically a Master Poster Featured Poster

or else you can use an array of FILE* if you want to use them elsewhere in the program. or write a structure with elements as FILE* and filename and use an array of that structure.

Agni 370 Practically a Master Poster Featured Poster

You need to give more info dude. As far as usage is concerned just look into any python tutorial on WWW

Agni 370 Practically a Master Poster Featured Poster

i dont think you should assign a char inside double quotes. Try

play[2] = '*'
if (play[2] == '*')

Agni 370 Practically a Master Poster Featured Poster

The size of the array has to be known at compile time. If it has to be decided at run-time please use dynamic arrays. When you used #Define the size was known at compile time hence it worked.

Agni 370 Practically a Master Poster Featured Poster

hex2bin[h] will give the value for the key 'h'.
i executed each statement separately, without declaring the dictionary and the output will make things very clear to you

>>number=1000
>>for h in '%X'%number:
        print h

3
E
8

now you can see that 'h' gets values 3,E,8. All these values are 'key's in the dictionary hex2bin. lets see what are the values for each key

hex2bin[3] = 0011
hex2bin[E] = 1110
hex2bin[8] = 1000

0011 1110 1000

hence 'join' is joining these 3 strings and stripping(lstrip) the leading 0's hence the output

1111101000

sneekula commented: good explanation +4
Agni 370 Practically a Master Poster Featured Poster

Algo will be:

1>divide the number by 10.
2>print the remainder or store it in an array.
3>assign the quotient as the original number and loop steps 1-2-3 till quotient it less than 10
4>print the last digit or store it.

Now you should have each digit.

Agni 370 Practically a Master Poster Featured Poster

One more way is to use a single dimension array. You can as easily take all the inputs from the users and then declare a single dimension array dynamically, size would the product of the the dimensions. and then while accessing the elements you can use pointer arithmetic.
something like:

//taking inputs as rows n cols
                int* arr = new int[rows * cols];
	int k = 0;
	for (int i=0;i<rows;i++)
	{
		for (int j=0;j<cols;j++)
		{
			arr[i*cols+j] = k++;
		}
	}
                // print the values row wise
	for (int i=0;i<rows;i++)
	{

		for (int j=0;j<cols;j++)
		{
			cout << arr[i*cols+j];
		}
		cout << "change of row" << endl;
	}

You can easily extend this for 3D arrays now.

Agni 370 Practically a Master Poster Featured Poster

OK my bad.. i didnt see that "Status" is declared right above in the class defintion and it's an Enum. Please ignore my post. Though you can still read about 'operator overloading' if you feel like.

sorry for the confusion

Agni 370 Practically a Master Poster Featured Poster

Where is 'Status' defined?? .. Basically 'Status' is not a native Datatype of c++ and so it doesnt have a predefined '==' operator for it. So you need to overload the particular operator before you do something like Status == xxx.

Read more about the topic "Operator Overloading" and you will understand.

Agni 370 Practically a Master Poster Featured Poster

Even then output might not be what you desire, getc returns the character currently pointed and also advances the position indicator by 1. so it'll always stub the first char from the output. since you're already checking for the 'eof' you dont need this extra check using getc. You can completely remove that while loop.

what was wrong with 'cout' though?

Agni 370 Practically a Master Poster Featured Poster

>>I.e. if we open a text editor will we find threads inside?

Text editor will definitely be multithreaded. Imagine a scenario where you send one document for printing and are writing into another document. Almost every application we use in our day to day lives will be multithreaded. The fast CPU speeds, huge amount of RAM's in the systems today make it almost mandatory to write multithreaded code to take full advantage of the processor.

Agni 370 Practically a Master Poster Featured Poster

ur most welcome ...

Agni 370 Practically a Master Poster Featured Poster

Dont replace earnedAmount, just change this line in 'sodaDisplay' method

double earned = 0;

to

static double earned = 0;
Agni 370 Practically a Master Poster Featured Poster

You are initialising 'earnedAmount' to '0' in every call of 'sodaDisplay' method. It should be initialised only once. Make it static and try.

static double earned = 0;
Agni 370 Practically a Master Poster Featured Poster

i'm trying to execute this program and everytime it tells me the same thing..

Welcome to the imaginary drink machine!
Please choose your icey cool beverage!!
---------------------------------------
1. Cola $0.75
2. Root Beer $0.75
3. Lemon-Lime $0.75
4. Grape Soda $0.80
5. Cream Soda $0.80
6. Nothing thank you
-->1

You chose Cola! That will be .75 cents!
Please insert money (in 0.00 format):0.75
Now how did you manage to enter that?
Please enter a POSITIVE amount of money!

isn't 0.75 positive? moreover y should it ask me to enter the amount when it's already shows how much it costs? System can itself take that amount.

Agni 370 Practically a Master Poster Featured Poster

hi..can you please post the 'correct' version of code using code tags and also the errors in one single post. That ways it'll be easier for people who want to help.

Agni 370 Practically a Master Poster Featured Poster

is the stack.cpp also having a main?

Agni 370 Practically a Master Poster Featured Poster

you can use

system ("sh scriptname");

Agni 370 Practically a Master Poster Featured Poster

The code could look like

if (  ( i%2 ) == 0 )
       {
             nEvenSum += i; //Sum of even Numbers
       }
       else
       {
              vOddNumber.push_back(i);//Storing all Odd Numbers
              nSumOddSquare  += ( i*i ); // Sum of square of odd numbers
       }

Hope this is your requirement

incase you didnt read the post by niek_e, he mentioned that % operator needs to be used. The idea was to give a direction to the OP, so that he can then find things on his own. No use giving the entire solution on a platter. No need for spoon feeding.

Agni 370 Practically a Master Poster Featured Poster

Thanks for the response and the link. As far as I can tell, I'm doing it right, but I still get the same result: the error message and no output file. Here's my updated code. As you can see from lines 16 and 17, I tried using both "ios" and "fstream" in front of "in" and "out". Neither worked. I didn't get the message "badbit is set" in line 24, so that means that it must be the failbit, right?

// This program creates an output file that will be read by another
// program while this program is still writing to the output file.

#include "windows.h"
#include <fstream>
#include <iostream>
using namespace std;

int main ()
{
	fstream outs;
	cout << "Going to sleep\n";
	Sleep (5000);
	cout << "Waking up: Opening log file\n";
	
//	outs.open("DummyLogFile.txt", ios::in|ios::out);
	outs.open("DummyLogFile.txt", fstream::in|fstream::out);	
	if (outs.fail())
	{
		cout << "Unsuccessful opening log file for output\n";
		
		if (outs.bad ())
		{
                      cout << "badbit is set\n";
                }
         }
	else
		cout << "Successful opening log file for output\n";

	for (int i = 1; i <= 10; i++)
	{
		cout << "Line " << i << ": Hello world\n";
		outs << "Line " << i << ": Hello world\n";
		Sleep (1000);
	}
	outs.close ();
	return 0;
}

i dont see anything wrong with the code above and when i executed this i got this output

Going to sleep
Waking up: Opening log file
Successful opening log file for output
Line 1: Hello world
Line …

VernonDozier commented: Thank you for taking the time to run my code. +2
Agni 370 Practically a Master Poster Featured Poster

kinda repetition, wrote it parallely i guess, but sometimes redundancy is good for driving a point home :) ...

n also after reading vijayan's post i realised that i made a mistake, if class A has a virtual dtor, that would be enough.

Agni 370 Practically a Master Poster Featured Poster

and when i tried compiling it using 'cc' it went just fine :-( ...

i suspected that this could be happening because you dont have a virtual dtor defined for the classes. Since you are pointing a base ptr to a child class, when you say delete b you dont really delete the child class. only the base class gets deleted. To make sure that the child class dtor also gets called both the classes should have a virtual dtor.

Agni 370 Practically a Master Poster Featured Poster

And there's a better way to do it if you have to use the dynamic array, you can increment the ptr everytime instead of using the index and then you can sum it also in the same place.

N I think i found quite a few bugs !!!

Agni 370 Practically a Master Poster Featured Poster

Also if you decide to use 'new' to allocate memory in your program, dont forget to delete it when its done. For arrays:

delete [] ptr;

Agni 370 Practically a Master Poster Featured Poster

From your logic you didnt need an array of integers at all. you are writing the value to the same pointer every loop. if you want to use the array do something like this.

cin>>ptr[count]

and then later sum up the array. or else simply use an int var and do something like this

#include <iostream>
using namespace std;
int main()
{
	int x,sum=0,count;
	int ptr;
	cout<<endl<<"How many numbers?"<<endl;
	cin>>x;
	//ptr=new int[x]; not needed
	for(count=1;count<=x;count++)
	{
		cout<<endl<<"Enter "<<count<<"th number:";
                                ptr = 0;
		cin>>ptr;
		sum+=ptr;
	}
	cout<<endl<<sum;
	return 0;
}
Agni 370 Practically a Master Poster Featured Poster

when we do

CandyBar *Candies = new CandyBar[3];

we are allocating memory to hold 3 elements of CandyBar type and returning the pointer to the base address of this memory. This address will actually be same as the address of the 0th element.

both CandyPointer abd Candies point the same memory location. however for better understanding he has assigned the address of the 0th element to CandyPointer. also if he were to put this in a for loop and access each element of the array then he can use the same pointer and not lose the base address.

most importantly in C++ arrays, index starts from 0. That is the 1st element is Candies [0]

Agni 370 Practically a Master Poster Featured Poster

Because they are not!!!.. In the class definition of CSci_Course you have not declared these functions.

Agni 370 Practically a Master Poster Featured Poster

Since its a beginner assignment i guess that's how you are supposed to take the inputs. i dont think you have too many inputs so this shouldn't be too time consuming.

Agni 370 Practically a Master Poster Featured Poster

how do I enter the name, length, and time for each course?

That's the only question? i find it strange that you could write a polymorphic code, use virtual functions but find it difficult to get the input!!! arn't those the values you are passing in the ctors?

Agni 370 Practically a Master Poster Featured Poster

To start with change

findArea(double&;double &)

to

findArea(double&,double &)

replace the ';' with ','

arguments in a function defn n decl are separated by comma not semi-colon