dkalita 110 Posting Pro in Training

i have made the transpose code but dont know how to do with pointers.if u say i can post it without pointers

yes u can do that.
But don't get so confused with pointers. They are not that complex as u think. Pointer is nothing but a value only but this value is a memory location.
U can read more about pointers. Do google, or read any book. There is nothing to panic about pointers.

dkalita 110 Posting Pro in Training


You might start by reading this Microsoft article

Hi, I have downloaded the standard and read it befor( but not the whole of it). But its too complex and I thought may be there is some simpler way to do so.
And I meant *.doc generated from MS Word only :)

dkalita 110 Posting Pro in Training

i try that ..
not work ^_^

do the initialisation in the default constructor then if u want.

dkalita 110 Posting Pro in Training

ok, i understand now, that it will not do putchar(' ') because the START has true value, so it will ignore all the white spaces until the first letter :)

but how to manage, that the output won't end with one space as it ends in this case.. i cant figure out how to replace last white space with \0, any ideas ?

use one more flag for that as

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
int c;
    int start= TRUE;
    int spacePrinted=FALSE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          spacePrinted = FALSE;
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
        }
          if (c != EOF)
          {
                if(start==FALSE && spacePrinted==FALSE)
                {
                       putchar(' ');
                       spacePrinted = TRUE;
                }
                putchar(c);
                start = FALSE;
          }
    }
}
dkalita 110 Posting Pro in Training

thats whats happen with me .

u mean
cin>>name;
worked in your compiler?

dkalita 110 Posting Pro in Training

ya,
thats the proper way of maintaing a log.

dkalita 110 Posting Pro in Training

Yes you can. But then you have an uninitialized variable in your program. That's a bad thing. That's why I said: string name="";

yes you are right but some compiler do not allow u to initialize a data member of a class like that.
Even I am getting the following error while trying to do so

error: ISO C++ forbids initialization of member `name'

This is the program that worked fine in my compiler(in linux)

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name;
          char status;
 public :
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name;
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return 0;
}

when i tried to use getline(cin, name) that statement is skipped. The user is not prompted for any input and goes for the next statement.

dkalita 110 Posting Pro in Training

please help for this code. if anyone have it please send me. thanks

IMPORTANT:
1. this is not a code repository.
2. We help those who show some effort.

dkalita 110 Posting Pro in Training

i try this ,,
but the program skip this process
ask me to put the "status" Dirct .

are u getting still more errors. Put them in here then. Will have a look at it.

dkalita 110 Posting Pro in Training
string name="";

u can write

string name;
dkalita 110 Posting Pro in Training

hi,

just want to ask, is it possible to restrict friend acess to a single class member function only?

in other words, if class A grant class B friend access to class A member function, then class B can call that class A function.

*note: this is suppose to be a workaround to the inability (my own) to pass class member function pointers into another class.

thanks in advance!

nope. A friend class can access all the members of a class.

dkalita 110 Posting Pro in Training

First of all I am suprised that the first code you works.
Reason? You did not initialize ch, yet you are able the output it the first time you do the while loop.

Yes u dint initialised your variable.
But

char ch = ' '; // instead of char ch;
/*Yes, he will also output a ' ' in the beginning of the output, but we ignore that part*/

This will print an extra character which is not there in your file. So its better to do it as u told u did by reversing the sequence of the two statements.

while(!in_stream.eof()) {	
      in_stream.get(ch);
      cout << ch;	
}
dkalita 110 Posting Pro in Training
fourMatrix(fourVector &i, fourVector &j, fourVector &k, fourVector &l): i(i),j(j),k(k),l(l){	}	
fourMatrix(fourVector i, fourVector j, fourVector k, fourVector l): i(i),j(j),k(k),l(l){

those two are the same prototype.U can declare only one of them.

Let me explain:

Say u have two functions:

void test(int x);
void test(int &x);

when u invoke them

int c=3;
test(c);

which function should get invoked?

This bring ambiguity. Read the error properly that u had which clearly said that.


home/mark/Vega_lib/Source/Geom.h:52: error: call of overloaded ‘fourMatrix(fourVector&, fourVector&, fourVector&, fourVector&)’ is ambiguous
/home/mark/Vega_lib/Source/Geom.h:7: note: candidates are: fourMatrix::fourMatrix(fourVector, fourVector, fourVector, fourVector)
/home/mark/Vega_lib/Source/Geom.h:5: note: fourMatrix::fourMatrix(fourVector&, fourVector&, fourVector&, fourVector&)

dkalita 110 Posting Pro in Training

A quick question: I have been writing a small program to simply read a file and send to cout.

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

int main() {
	char ch;
	ifstream in_stream;
	in_stream.open("self.cpp");
	
	while(!in_stream.eof()) {
		cout << ch;
		in_stream.get(ch);
	}
	
	in_stream.close();
	return 0;
}

This works ok, except that the last '}' of the file is printed twice.

However, if I reverse the order of lines 11 & 12 (so that in_stream.get is called before cout << ch), the last character of the file is printed only once so the program works correctly.

I cannot figure out the reason for this subtle difference. Could anybody help me?

Thanks.

its because the last call to in_stream.get(ch) stores the last character in the file. But probably its not the end of file yet, because it still have one more character: EOF. So the cout is again executed. But at this point, the character ch has the previous value it read from file since the very last read reads EOF and hence does not store in that variable which have its previous value intact.
That is why its printing the last character twice.

But that was not the very exact explanation though.

dkalita 110 Posting Pro in Training

Wow, thank you so much for the detailed explanation.
This means I have to parse the logfile, read the contents of the log line by line until the counter value found at the end of the file, if found store it in the variable and start incrementing. Read first the contents of the logfile before writing anything?

thanks
gilmar

absolutely..............

dkalita 110 Posting Pro in Training

but with that u will have only one char so do something like
char name[20];

dkalita 110 Posting Pro in Training
using std::cin;                //  using std::setprecision;
using std::cout;                 using std::string;
using std::endl;               //  using std::streamsize;

make it a one statement as

using namespace std;

I am not sure of why the error is coming because i tested the same in my machine in linux and it was working.

dkalita 110 Posting Pro in Training

By default the access specifier is private in a class and hence u are not able to access the ginfo() and pinfo() method of the class STD1.
U have to set them as public.
Do

public:
    void ginfo();
    void pinfo();
dkalita 110 Posting Pro in Training

u can store the counter value at the end of the log file. Next time its opened, goto the end and read that value, increament it, and write to the file after writting everything else in it.

Let me explain:
Lets start with an empty logfile.
Since it doesnot exists, u create one. Write all the logs u want in the file. Write 1 at the end. or use some format like "<<1>>". So that u can differentiate it from other logs written to the file.
Close the file.

When u reopen the file next time, it already exists. Now goto the end. Read <<1>>. U will get the 1 from here. Write all the log entries to the log file. At the end write <<2>>. and so on.
and so on .........

U can use any format (such as (1), [1], $1, etc.) of your wish which u can distinguish from a normal log message.

dkalita 110 Posting Pro in Training

hi
I want to retrieve the contents (including the tables) from a .doc file using C in linux.
If I can get the representation of the .doc file, then also I can proceed.
I have though done that but it has some bugs because I am using a logic which fails in many situation.

Any help would be appreciated.

thank a lot.

***NB: I have posted the same query in C++ forum also some days back for doing the same in c++.

dkalita 110 Posting Pro in Training

How do you create a program in c++ to find the closest pair of points in a 2D plane recursively?

Its not about c++.
Its about getting an algorithm first.
The implementing language is not a very big deal if u have a good algorithm. First get an algorithm. If u r not very cmofortable with c++ u can implement in c. Then u can identify the processes and data being used and make an object design for that and proceed with c++.
google for an algo first. (following are some links which u can read)
http://en.wikipedia.org/wiki/Closest_pair_of_points_problem
http://www.facweb.iitkgp.ernet.in/~arijit/courses/autumn2005/close.pdf

dkalita 110 Posting Pro in Training

I have to manipulate strings so that, we need to check if a string needs to be combined with another string. Need to use a library function for this.

Suppose, we have

S1. This is an apple
s2. apple is sweet
so, the combined line should be: This is an apple is sweet

s1. This is an apple
s2. e that I bought
Combined: This is an apple that I bought

I used nested for loops for this and it makes it too complicated. Is there a string library function that I can use?

I will have bunch of lines of sentences, and I need to combine them to form one sentence.
I need to combine lines that match the most, not just 2 lines that match.

U can use the functions strstr() and strcat() to do the above. Read their manual.

dkalita 110 Posting Pro in Training

I test ran your code and got the following output:

Enter the maze's dimensions separated by a comma.
Format x,y: 3
5

cout << maze[][].*Wall; in LoadMaze()

0,0 stores 1 1 1 1
0,1 stores 1 1 1 1
0,2 stores 1 1 1 1
1,0 stores 1 1 1 1
1,1 stores 1 1 1 1
1,2 stores 1 1 1 1
2,0 stores 1 1 1 1
2,1 stores 1 1 1 1
2,2 stores 1 1 1 1
3,0 stores 1 1 1 1
3,1 stores 1 1 1 1
3,2 stores 1 1 1 1
4,0 stores 1 1 1 1
4,1 stores 1 1 1 1
4,2 stores 1 1 1 1

cout << maze[][].*Wall; in main()
1

........................................................
I am not sure of why u r getting that 171 in your output...........

dkalita 110 Posting Pro in Training

may be u can do it as

void ConcreteVisitorA::VisitElement(Element e)
{
 
	int numNodes = e.GetNumNodes();
	int numAttrs = e.GetNumAttrs();
	cout << "Visitor has found " << numNodes << " noes\n";


              Visitor tempV;/*set all the necessary data members*/
	e.nodeVec[0]->Accept(tempV);
		
}
dkalita 110 Posting Pro in Training

U can do the same as follows:

void write(char string[])
{
  int i;
  FILE *file;
  char *strTemp=(char *)malloc(strlen(string)+1);
  strcpy(strTemp, string);

  file=fopen("log.txt","ab+");

  if(file!=NULL)
  {
	  for(i=0;i<strlen(string);i++)
		strTemp[i]^=0xff;
	  fputs(strTemp,file);
                  free(strTemp);
  }

  fflush(file);
  fclose(file);
}

This way u will save the number of operations done to the string.

dkalita 110 Posting Pro in Training
void getdata(int &major, string &lastname, float &credits, float &gpa, float &tuition, int &senior, int &freshman, int &sophomore, int &junior, float &totaltuition, float &totalcredits, float &totalgpa, float &maxgpa, float &maxmathgpa, float &maxcisgpa, string &lastname, string &newlastname, string &mathlastname, string &cislastname);

Use a struct variable to store the student info.
Dont do things like above, it complicates your code a lot.

typedef struct
{

         char fname[20];
         char lname[10];
         /*other student info*/
}student;

void getData(student &st);
dkalita 110 Posting Pro in Training

its a good suggestion by dkalita.. if u dont want to change the return type u can call the switchuser function inside the if block as follow ...

void TicTacToe::postMove(int row, int col, char value)
{
if (theBoard[row][col] == '-')
{
theBoard[row][col] = value;
//call the switch user function here...then u can return to the block  // which called this function
}

else

cout << "Space is already taken, please choose a different one." << endl;
}

Cheers ,
saradha

u can do that. But it's not a good OOP practice.

dkalita 110 Posting Pro in Training

that's what i thought. Its crazy i don't think it is possible without helper functions and you probably want to keep head private.

offcourse U shouldn't make head public because its of no meaning to others and it should not get modified from outside the class.

dkalita 110 Posting Pro in Training
void TicTacToe::postMove(int row, int col, char value){
     if (theBoard[row][col] == '-'){
          theBoard[row][col] = value;
     }
     else
          cout << "Space is already taken, please choose a different one." << endl;

make the return type of the above function as bool. Return false if the space is already occupied.
Dont call the switchPlayer() method if postMove() returns false.

dkalita 110 Posting Pro in Training

there is no way other than that or making the head public.

U can write the third function with the same name without having any parameters.

dkalita 110 Posting Pro in Training

how do i do that? and their is still something wrong with the code. :(.

that answer was for your last post before you edited that.

Write a third function without any argument which calls your recursive function inside it passing the head.
Call this third function from main().

dkalita 110 Posting Pro in Training

declare your p as static in the show_sllist() method

dkalita 110 Posting Pro in Training

give it a try with the following

string[i]^=(char)255;
dkalita 110 Posting Pro in Training
reverseArray(intArray,low,high);

what is the value of low and high. U didn't initialized them.
Would u plz first go through your code and do a dry run using pen and paper.

dkalita 110 Posting Pro in Training

check the prototype of the function reverseArray()

dkalita 110 Posting Pro in Training

I fix that but I need help in writing the body of that +operator overloading function.
Thanks,

int LargeDigit::operator +(const LargeDigit &digit)
{
     return (this->intz + digit.intz);
}
dkalita 110 Posting Pro in Training
month = atoi(strtok(s,"/,:\n"));
day = atoi(strtok(NULL,"/,:\n"));

u ingnored what i told u in my previous post in these lines.
If strtok() returns NULL u will have atoi(NULL)

dkalita 110 Posting Pro in Training

and plz, can u explain me, why using your code was more successful than mine ? what did that #define TRUE, #define FALSE do excactly /, and using this in the code, i relly want to understand it

read more on macros in C

dkalita 110 Posting Pro in Training

use a flag for that as follows

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
int c;
    int start= TRUE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          if(start==FALSE)
                 putchar(' ');
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
          }
          if (c != EOF)
          {
                putchar(c);
                start = FALSE;
          }
    }
}
dkalita 110 Posting Pro in Training

What should the yylex return, an int value? Does it need to correspond to the %token 's that we declare?
Thanks

yes.
yylex() returns the token value as integer.
The token gets stored in a char * called yytext. U have to access that variable to get the actual text token.

u will have to declare this variavle also as "extern char *yytext;" in the file where u want to use it.

Read about flex and yacc tool. Read more on developing parser.
I hope U have your grammer ready for building your parser.

hope that helps..............

dkalita 110 Posting Pro in Training
strcpy(array[daysize]->appts[0]->subject, strtok(NULL,"/,:\n"));

avoid something like that. It might give segentation fault if there is no more tokens (strtok() returns NULL).

Make a check before doing any operation on the string pointed to by the address returned by the strtok() function.

char *c = strtok(NULL, "/,:\n");
if(c!=NULL)
       /*proceed*/
dkalita 110 Posting Pro in Training

It's a private field which I can't change.. and my teacher won't let me :( So I think we need another way around this :S

then i think u can consider 0(zero) as an invalid value.

dkalita 110 Posting Pro in Training

i guess u r looking for something like

struct myData
{
    int data;
    bool valid;
}

vector<myData>   setList;

slight modification to it

typedef struct
{
    int data;
    bool valid;
} myData;

vector<myData>   setList;
dkalita 110 Posting Pro in Training

Wait, this can't work because I am not allowed to change my vector <bool> setlist because it's a private data field in my class.

Did you mean for me to change my bool vector to a stuct vector?

yep

dkalita 110 Posting Pro in Training

Ahh I see now. okay thanks.

Got the error fixed too :)

u welcome.
hope u can mark this thread as solved i guess.... :)

dkalita 110 Posting Pro in Training

Hmm okay. Can you please explain what int data is used for?

It is the "int x" that u have used in your code.
I just gave it a different name.
(NB. Use meaningful variable name in your program. This makes it more meaningful when someone sees the code.)

I get this error when compiling:

expected init-declarator before "setlist"

for that u have to post your code so that I can see where the error occured...........

dkalita 110 Posting Pro in Training
int operator+::LargeDigit(const VeryLongInt &digit)
{
   return  digit.intz+=digit.intz;
}

it should be

int LargeDigit::operator +(const LargeDigit &digit)//SEE THE SYNTAX properly
{
     /*your code*/
}

where did u get that VeryLongInt ........?????
U are overloading the operator + for the class LargeDigit right ...!!!

dkalita 110 Posting Pro in Training

i guess u r looking for something like

struct myData
{
    int data;
    bool valid;
}

vector<myData>   setList;
dkalita 110 Posting Pro in Training
result = sqrt((sqr(c))-(sqr(b)));

if c>b then u will have sqrt(-ve number).

U cant calculate sqrt for a negative number.

dkalita 110 Posting Pro in Training

am trying to make a timer circuit with the help of 89c52 micro controller. I have one assembly language program, but the programming kit supports only to C language. I want to translate assembly program to C program so that I can use it for the above mentioned micro controller. If anyone of you know how to translate, then please do tell me. Thank you. If any other information you need related to the circuit please ask about it.


_______________________-
SEO

U can write a C program where u can embed your assembly code.
See the following link on how to embed assembly code in C.
http://home.pacbell.net/bill_gi/bill/mentor_asmC.txt