Agni 370 Practically a Master Poster Featured Poster

I have a vector of a structure..

say

struct employee
{
string name;
int age;
int empId;
};

and a vector of this structure

RWTValOrderedVector<employee> vec;

suppose this vector has 4 entries. Now if i want to find in this vector for employee information of a specific employeeid, how do i do that without looping through the vector and fetching each structure and comparing the empId value of each structure with the i/p?

Agni 370 Practically a Master Poster Featured Poster

exactly thats y i mentioned that use environment variables like $MYPATH but yes its always there that you might change the drive in which you place the code etc. but after a point the dir structure has to be the same as urs. i mean suppose you put it in

"e:/linux/eclipse/workspace/" and set $MYPATH as e:/linux then ur makefile will have

$MYPATH/workspace

now the other person might store it in

"c:/temp/project/workspace"

he can set $MYPATH as c:/temp/project and the makefile will work for him provided the final folder is same as urs, which is workspace in this case..

got it?

Agni 370 Practically a Master Poster Featured Poster

sounds good .... or how bout 'a junior poster in training' actually gets access to some training material from the site.. or he's assigned an expert as a buddy who he can go to once in a while for help :)

Agni 370 Practically a Master Poster Featured Poster

Then put it in the makefile and give the makefile with the source code for compilation and yes to make sure the makefile works for anyone, make sure the paths are not hardcoded. use environment variables like $PATH etc. so that it works for anyone in any directory structure..

Agni 370 Practically a Master Poster Featured Poster

try

#include <iostream> //removed .h in the end
#include <stdlib>

Agni 370 Practically a Master Poster Featured Poster

either you give the complete path in the include statement. or else what you can do is that you can add the complete path in the include path of the compiler. in command prompt we do it by using the compiler option -I. eg

gcc -I<path> file.cpp

you can set this in the makefile or
if its GUI there must be some option to set this path for the compiler.

Agni 370 Practically a Master Poster Featured Poster

wow... can that be done in c++?? can someone tell me which API's to use for this?? would luv to give it a shot...

Agni 370 Practically a Master Poster Featured Poster

i understand that... n i'm not even looking for money at all .. n would myself keep doing this coz its so much learning for myself too .. i was just trying to bring out suggestions from ppl bout things they think would make it more fun... even if they r not implemented its ok ... just some creative brainstorming :)

Agni 370 Practically a Master Poster Featured Poster

well i just meant some non monetary ones... n its nothing to get so worked up about.. just a casual thought .. i thought this was a place to discuss such things ...

Agni 370 Practically a Master Poster Featured Poster

hey guys ...
i was wondering shouldn't we awarded some kind of privileges as we move up the rank?.. for example when a light poster becomes a junior poster(like me :), n i'm so proud if myself) say he can be given the privilege of getting one query answered by a PM by one of the Mods or access to some mailing group, anything.. wouldn't that motivate me more to keep trying?? though believe me the title itself makes me so damn happy but was just wondering ..

what do u guys think??

Agni 370 Practically a Master Poster Featured Poster

Add to the question above. Now what i want to implement is that i want to decouple the server from the rest of the logic. i.e. once the server gets the request, it just waits for anyone to query it for the request string. as of now the server calls the manager n passes the string and everything is in one big .exe. Now how do i implement this? no i'm not asking for the code, just a design, like can i keep the rest of the code in a separate dll and keep polling the server for this string or something like that?

Agni 370 Practically a Master Poster Featured Poster

Guys i have a design where in i have 6 classes called

1)HttpServer
2)ParserClass
3)InputInterface
4)Cartonization
5)OutputInterface

and then i have a
6)Manager class.

HttpServer gets the request xml as a string in request body. ParserClass parses the string xml and stores value in variables. inputInterface inserts the values in inputTable, Cartonization Class does some processing with these values. OutputInterface inserts processed values in OutputTables then we re-create an ouputxml and send it back as response.
The various functionality is controlled by Manager. Manager takes i/p string from server, passes it to parser, parser returns some values,manager gives it to i/p interface etc. Now my question is that to all this Manager needs to have objects of all these classes. none of these functions are static. Should i make all these classes as class member variables of the manager class or should i create the objects as and when required and use them? what will be a better design?

thanks
chandra

Agni 370 Practically a Master Poster Featured Poster

where's the code? also this algo will always work only for 4 digit numbers, with a little more effort you can convert it to a general code for any no. of digits in the number..

Agni 370 Practically a Master Poster Featured Poster

when you declare a function as const, it implies that you cannot change the state of the object inside that function. that means you cannot change the value of any member variable inside the function and you cannot make a call to any non-const function either. that is y its not allowing you to modify 'x' inside add, however when your remove the const your are able to modify it. it has nothing to do with the variable being private, even if it was public it would not have allowed you to modify it.

superjacent commented: Very helpful. +1
Agni 370 Practically a Master Poster Featured Poster

y do you have to write this program?

Agni 370 Practically a Master Poster Featured Poster

but you needed to re-insert the 84 char string again into the new string..rt?

Agni 370 Practically a Master Poster Featured Poster

whats the error that you're getting??

for array of structure say

personnel arr[20];
arr[0].name = "blah";
..
..
arr[1].name = "blah";

and so on and so forth. you can put this in a loop to take 20 inputs

Agni 370 Practically a Master Poster Featured Poster

got it...

Agni 370 Practically a Master Poster Featured Poster

and i just tried, using the >> operator also takes you to the next line everytime.

Agni 370 Practically a Master Poster Featured Poster

for 1> suppose you have a char and you have to typecast it to int

char a = 'r';
cout << (int)a; //cast char to int

for2> you can use 'getline' without the delim parameter, in that case it will read till it encounters '\n' or eof

char a[4];
char b[4];
indata.getline(a,4);
indata.getline(b,4); //reading next line
Agni 370 Practically a Master Poster Featured Poster

how much can you pay ;) ??

Agni 370 Practically a Master Poster Featured Poster

At what point are you stuck?

Agni 370 Practically a Master Poster Featured Poster

the correct condition is

if((yy%4 == 0) && !(yy%100 ==0) || (yy%400 == 0))

probably you can have a while loop to keep taking inputs and returning the number of days till the user says i'm done.

so all your code can be put inside a while loop and you can ask the user if he wants to continue or not.

Agni 370 Practically a Master Poster Featured Poster

Its kinda long but here it is...

// Program assignment #1
// Brandon Moffett

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

// function prototypes

int main()
{
    
    int mm,dd,yy,mm2,dd2,yy2,maxdays,day;
    char s,s2;
//prompt the user for input
cout << "Please input your birthday using this format (MM-DD-YYYY)\n";
cin >> mm;
cin.get(s);
cin >> dd;
cin.get(s);
cin >> yy;
cout << "Please input the current date using this format (MM-DD-YYYY)\n";
cin >> mm2;
cin.get(s2);
cin >> dd2;
cin.get(s2);
cin >> yy2;

  switch (mm)
     {
     case 1: maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are acceptional, please continue...\n";
             else
                 cout << "Invalid day of the month : " << dd << endl;
                 break;
     case 3:maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are acceptional, please continue...\n";
             else
                 cout << "Invalid day of the month : " << dd << endl;
                 break;
     case 5:maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are acceptional, please continue...\n";
             else
                 cout << "Invalid day of the month : " << dd << endl;
                 break;
     case 7:maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are acceptional, please continue...\n";
             else
                 cout << "Invalid day of the month : " << dd << endl;
                 break;
     case 8:maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are acceptional, please continue...\n";
             else
                 cout << "Invalid day of the month : " << dd << endl;
                 break;
     case 10:maxdays = 31;
          if (dd <= maxdays)
             cout << "Dates are …
Agni 370 Practically a Master Poster Featured Poster

can you post that code? i dont know y you need the loop...

Agni 370 Practically a Master Poster Featured Poster

To understand more read about 'datatypes' in c++ ..

Agni 370 Practically a Master Poster Featured Poster

that was a very stupid answer indeed. what he wanted was some kind of suggestion from personal reading. i.e. if you had used some book which you found really good you could have suggested that, instead of trying to be extra smart ...

Agni 370 Practically a Master Poster Featured Poster

i think i gave the solution to your problem in my first post

Agni 370 Practically a Master Poster Featured Poster

on my first glance i can c a lot more errors once you do this you might have to solve those too..

Agni 370 Practically a Master Poster Featured Poster

dude your code is too difficult to read, next time please indent it properly and put in CODE tags

however i can make out that you have not overloaded the operators in your class. The operator funtions need to be declared as member functions of your class

got it?

Agni 370 Practically a Master Poster Featured Poster

i guess what you want to do is create variables of type tree, for that you dont need to do typedef. you can say

tree banyan;
tree apple;

or else

struct tree{
int height;
int width;
int weight;
} banyan, apple;

and they will be two separate variables of type tree.

Agni 370 Practically a Master Poster Featured Poster

setting up the loop is easy

you read the number n then put a for loop

for(int i=0;i<n;i++)
{
// here your code for checking of divisibility of 'i' will appear. it'll be an if-then-else conditional check.
}

hope this helps

Agni 370 Practically a Master Poster Featured Poster

let me start by telling you that i was solving it more for myself than you, i was not very sure about the ifstream/ofstream fns so i solved it and then posted the soln also, as a result i didnt really bother too much about solving the exact qs.. now i can ans the qs..

[TEX]1>"the ASCII value of your character "h" is "104"[/TEX]

for this you simply need to typecase line1 variable to int before giving it to cout

[TEX]2>for the 2nd part i wasnt sure if i had to break it up in to to seperate functions or not[/TEX]

upto you to decide

[TEX]3>next i was thinking once i figured out if i need two functions t how was i going to get the 2nd line of the" data.txt" files only to read the 46 and 54 .
am i going to need a ignore statement ?[/TEX]

not sure what ur saying here. in my code above i'm able to read the two lines and perform the calculations

[TEX]4>where the variables i used bad ? i see you changed them for the second part of the program[/TEX]

i just added a few more, sum and product were added to write into the new file and some char arrays for getline functions.

[TEX]5>why did you remove parts of my header[/TEX]

i was not sure y they were added, so i removed them to start with, thinking that i will include if the compiler …

Agni 370 Practically a Master Poster Featured Poster

you are right, but there is some case in which it gives error if i dont include it with the #ifndef directive.. cant remember right now, but there was some error, may be at link time, will check and get back..

Agni 370 Practically a Master Poster Featured Poster

when you include one file in more than one places it might cause a redeclaration problem. to avoid that put ur includes in guards with ifndef and endif preprocessor directives.

eg:

person.h

#ifndef PERSON_H
#define PERSON_H

class person
{
\\\
};

#endif

and then wherever you include this file, do it like this

#ifndef PERSON_H
#include <person.h>
#endif

this will ensure the file does not get included more than once

Agni 370 Practically a Master Poster Featured Poster

and yes make sure you read the 'things to keep in mind' while using strtok or the result would be unexpected... dont want to tell you and spoil the suspense :)

Agni 370 Practically a Master Poster Featured Poster

'strtok' returns tokens in the string. Basically you put it in a loop, give the input string and a delimiter as arguments, it'll keep returning each token. you can put a counter and check for NULL token to exit the loop. for function signature try reading some doc.

Agni 370 Practically a Master Poster Featured Poster

if you post the code that YOU have tried then we can help you in debugging and solving the problem. but you cant just expect spoon feeding here..

ps: i just got ripped left-right-center for trying to solve a similar thread

Agni 370 Practically a Master Poster Featured Poster

ok

Agni 370 Practically a Master Poster Featured Poster
#include <iostream>
#include <fstream>

using namespace std;

int main ()
{

	//variables declared for fstream
	ifstream indata;
	ofstream outdata;


	//files to open and to close
	indata.open("c:\\data.txt");
	outdata.open("c:\\results.txt");

	char line1; 
	int line2a, line2b; 
	char val1[4],val2[4];	
	char delim = ' ';

	indata>>line1;
	cout << " The ASCII value of your character is " << (char)line1 << endl;
	;

	indata.getline(val1,4,delim);
	line2a = atoi(val1);

	indata.getline(val2,4,delim);
	line2b = atoi(val2);

	int sum = line2a + line2b;
	int product = line2a * line2b;

	outdata<<line1;
	outdata<<'\n';
	outdata << "The sum of the two numbers " << line2a << " and " << line2b << " is = " << sum << '\n';	
	outdata << "The product of the two numbers " << line2a << " and " << line2b << " is = " << product << '\n';	

	indata.close();
	outdata.close();

	return 0;

}

Does this solve your problem??

Agni 370 Practically a Master Poster Featured Poster

let me try and explain, overriding is a mechanism for achieving dynamic polymorphism and has nothing to do with accessing a function of one class in another. it allows a subclass to extend the functionality of a base class function. i hope u understand that 'dear' ...

Agni 370 Practically a Master Poster Featured Poster

dear u can acces the sum function of any class through this way try it out..
if u want addition of 2 no. in class A and class B as well
den instead of making same function again do overidding:)

excuse me ma'am.. it seems that you are totally confused amongst the various concepts of object oriented progamming.. which is very common.. so please take my suggestion and try and re-read all these concepts again and clarify your fundas.

Agni 370 Practically a Master Poster Featured Poster

> class name of that class whose function u r calling::then the function name();

even this is not correct unless you specify its a static function, which seems like a far cry for the original post at this time

Agni 370 Practically a Master Poster Featured Poster

well for accessing one class function in an other the easiest method is to create the same function in the other class or do over loading
like wise
class name of that class whose function u r calling::then the function name();

>well for accessing one class function in an other the easiest method is to create the same function in the other class or do over loading

i dont think thats the best advice to give... how can you access one class function from another by creating same function in another class?? where does overloading come in??

Agni 370 Practically a Master Poster Featured Poster

hey guys ...

Are there any people out here who've done their masters in comp science? .. need to know whats the best time to go for a masters? how easy or tough it is?? and most importantly how useful? i have a bachelor of engineering in electronics but i'm more inclined towards software now...

thanks
chandra

Agni 370 Practically a Master Poster Featured Poster

may b u can try opening the file in the append mode. in that case it would not overwrite

Agni 370 Practically a Master Poster Featured Poster

Just create file before the start of loop. inside the loop, keep writing to it. after the loop close it. have u tried reading the documentation for ofstream or fopen ? i guess you shd do that now

Agni 370 Practically a Master Poster Featured Poster

just type 'resize + array' in the search text box and you will find the answer.

Agni 370 Practically a Master Poster Featured Poster

whats the use of the const global variables? y r u re-declaring them in main? just think whats the objective of the code, what will be the min number or variables required,their types and usage and then re-write the code.

Agni 370 Practically a Master Poster Featured Poster

you have functions like fopen, fclose,gets,puts etc for file manipulations, provided by the standard libraries. look up in some documentation.