Agni 370 Practically a Master Poster Featured Poster

cool.. i'll send her a request :) ...

Agni 370 Practically a Master Poster Featured Poster

Hi Guys.. is there someway i can change my screen name from 'chandra.rajat' to something else ??...

-chandra

Agni 370 Practically a Master Poster Featured Poster

i dont think you have provided a body for the method 'GetRoomID'

Agni 370 Practically a Master Poster Featured Poster

but why are you taking the numbers into char arrays?

Agni 370 Practically a Master Poster Featured Poster

'Vector' - 'vector'

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

just pasting too much code is not going to help anyone, sometimes it can even confuse the person. It's better to give as much info as is asked.

Agni 370 Practically a Master Poster Featured Poster

i edited my post later, just read the last line again. when you swap the total, swap the exam id's as well. in short you will swap the entire structures and not just the totals.

Agni 370 Practically a Master Poster Featured Poster

where's the code to do sorting just the total?

at the time you swap the totals, you can swap the examid's also, i think that should work. what say?

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

what will be the functionality of the trigger?.. if it's to distribute the load then i think it should be a row-level trigger.

Agni 370 Practically a Master Poster Featured Poster

What do mean by working? The difference lies in their usage, in the way they are declared, their inheritance etc. but they work in the manner you specify them to work.

Agni 370 Practically a Master Poster Featured Poster

2 1/2 years for me .... and i realise that it'll take me time to be a pro in c++ . In contrast i see people who use Java become proficient much quickly. There was a time i was thinking of shifting to Java(around a year back) but then stuck to c++ and now i'm in love with it. It's always so challenging....

Agni 370 Practically a Master Poster Featured Poster

it would be nice if you tried compiling it and then let us know which lines are throwing errors and then we look into it. Also you done need to put everything in code tags, just the code will do.

Agni 370 Practically a Master Poster Featured Poster

"I dont comment my code, if it's tough to write it should be tough to understand"

Agni 370 Practically a Master Poster Featured Poster

you dont need to use 'size' in the if statement, you can compare the values itself, using the 'at' function was enough.

compare the values "exams.at(i).total.at()"

Agni 370 Practically a Master Poster Featured Poster

if( j < (j+1) )
{
//code
}

Agni 370 Practically a Master Poster Featured Poster

you can use any of the sorting algorithms. Try bubble sort, it's one of the easiest and since the number of elements is not too large you dont need to worry about performance.

before that you need to fix some other errors in your code too. within nested for loops that counter you use should have different names. all your nested loops have 'j'.

Agni 370 Practically a Master Poster Featured Poster

I want to sort the number in descending order...but how to declare a exams.at (i).total.at(j)" in if statement?

> you mean

if((exams.at (i).total.at(j)) < somthing)

Agni 370 Practically a Master Poster Featured Poster

There are some missing '{' brackets after line 69,75,80. Can you try after fixing them. and if that's just a typo then plz paste the corrected version.

Agni 370 Practically a Master Poster Featured Poster

if you tell us that in which part you're facing a problem or if there's some compilation error we might be able to help you.

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

2) tell the function the number of each dimension's element.

void function(int& aaa[][], int 1d, int 2d)

you dont need to say int& aaa just int aaa will be enough, also i think that you will have to give the 2nd subscript of the array int aaa[][col]

another method is to pass pointer to array

function(int (*p)[col],int row,int col)
{
      int* q = *p;
      for(int i=0;i<row;i++)
      {
          for(int j=0;j<col;j++)
          {
              cout << *q << endl;
              q++;
          }
      }
}

since 'p' is a pointer to an array, when we increment it, it points to the next memory address of its type, means the next array. Thus we used another pointer to be able to access each element. Just another way of writing the function.

Agni 370 Practically a Master Poster Featured Poster

use one array to store the score of each student and another to store the weight of each student. If you know the number of students beforehand then it's all the more easier.

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

That would fail the purpose of this community. When you ask questions here and people give answers it helps other's who might be facing similar problems. Just like you can find a lot of answers by going through previous threads.

Agni 370 Practically a Master Poster Featured Poster

Then what's the solution? i read the post on dynamic case after i posted this and think i read that c-style casting can help avoid this, is that right?

Agni 370 Practically a Master Poster Featured Poster

awesome is fine .. but i hope you understood your mistake... just taking his code blindly and using it will not help...

FYI you were not using recursion at all !!!

Agni 370 Practically a Master Poster Featured Poster

To assure that the base class is pointing to the correct child class we use 'dynamic_cast' . This will do a RTTI to make sure that the base class is actually pointing to class to which it's being downcasted to.

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

here atrr is declared as static as i result that the address that you are inserting into the vector is same everytime.

insResult = atrributeMap_g.insert(std::make_pair(atrr.name, &atrr));

as a result when you do

Itor->second->name;
Itor->second->id ;

you get the same values everytime.
can you print the address and confirm this?

Agni 370 Practically a Master Poster Featured Poster

You dont need to change anything in those functions. where are you populating this vector?

Agni 370 Practically a Master Poster Featured Poster

Not really... actually i was thinking of making a UI may b using java swing... need to make it in a kiosk form where i can even put a touch screen on top of it ... i get a feeling that using c++ might not be easy here... i'm also looking at other options for displaying graphics... do you have any suggestions?

sorry for the abstract sort of info.. the idea is still in a very nascent stage...

Agni 370 Practically a Master Poster Featured Poster

#ifndef hourlyEmployee_h
#define hourlyEmployee_h
#include "employee.h"

i dont think the file employee.h is getting included at all. You should do

#ifndef hourlyEmployee_h
#include "employee.h"
#endif

or infact you dont need to use the ifndef while including the file if you have already used them in the header file.

Agni 370 Practically a Master Poster Featured Poster

can you post the include statements?

Agni 370 Practically a Master Poster Featured Poster

have you put everything in 1 file or separate files?

CSci_41(string name, int time, int length) : CSci_Course()

you dont need to explicitly call the base default ctor. remove the call and try.

Agni 370 Practically a Master Poster Featured Poster

Reposting from another forum as i didnt get many suggestions there

Hi Guys,

In my project the user will enter the name of the organization and it's floor map has to be displayed. the maps have to be made by us and need not be complicated at all. what i want to know is that what technologies can i use to do this? the backend has to be in either c++ or java with an oracle DB. should i use CAD? as i've never worked on CAD before i have no clue how it'll get integrated with C++ and if it can be useful for me or not or can i use C++ to make the maps? they need not be 3d maps, it can b 2d but need to be very presentable/colorful/easy to read etc

any directions will be very helpful.

thanks
chandra

One suggestion i got was to use VB.Net. Is it that difficult to do it using c++? i'll have to learn VB.Net from scratch.

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

Agni 370 Practically a Master Poster Featured Poster

if i'm not wrong you can directly assign an integer to a double in c++, there's no need to do an explicit casting.

Agni 370 Practically a Master Poster Featured Poster

To give you a brief idea. When you allocate an array you are actually reserving some memory for storing data. now lets c

when you say

int Quantity[6]; you have reserved memory to store 6 int data type. This memory is allocated serially one after the other. so you can imagine it to be 6 blocks-each capable of holding an 'int'-placed one after another.

not how do you access each of these blocks? luckily for you have numbers assigned to each of them(for now you can take it this way, once you learn pointers you'll see exactly how it works) so you have 0 for the first block, 1 for the second block and so on. Thus to either extract the data from a particular location or to insert data into a particular location all you need to do is, go to that memory location using it's number. Quantity[0] for 1st location. now its easy, you can go to any location, get data/put data do whatever you want to :) ...

Note: this was just to get you imagining on the lines. now you can read furthur to get the nitty gritty... you might start enjoying c++

Agni 370 Practically a Master Poster Featured Poster

Post one such program where you used an array and it didnt work. we'll try and help you find the mistakes.

Agni 370 Practically a Master Poster Featured Poster

well there again a lot depends on what you are trying to achieve. but i can give you some examples.

->setmethods a usually void. all that this method does is set the value of a member variable. hence you dont need to return anything.
->as i had written earlier functions where the parameters are huge we prefer to pass them by reference and make the function as void. In that case we will avoid copying of the variables.
->A return value function example would be the 'getmethods' which you would use to retrive the value of some member variable that you would have set earlier.
->and then most of the time when you want some value from the function to be used in your function you will need a return-value.

Agni 370 Practically a Master Poster Featured Poster

There are a lot of considerations but to start with you can use one rule.

-> when you dont want to change the actual variable, you pass by value. in this case in a copy of the variable will be made in the called function and hence the original value will remain same.
-> when you want the value of the actual variable to change then you pass by reference. whatever changes you make to the value in the called function will change the value of the original variable in the calling function.
-> whenever the data passed is large, for examples structures or objects we prefer passbyref as a new copy will not be made.

you can explore more now...

Agni 370 Practically a Master Poster Featured Poster

Hi,

Suppose I have a character array array1[]={A,B,B,B,A,A}. Now I want to declare a structure with a pointer in it and make each array1 element point to the previous element.For example last array1 element 'A' will point to the previous 'A' which will point to 'B' and so on. Can somebody please help me with the coding?

Any quick help much appreciated.

Thank you

i think your prof wanted you to use link list. in a link list you can keep the pointer to the next element.

struct node
{
char a;
node* p;
}

here you can assign the valus of 'a' from the array element and then keep a pointer to the next element.