Sci@phy 97 Posting Whiz in Training

The flag should be of bool type, and you don't have to define anything (if it is really C++)

Sci@phy 97 Posting Whiz in Training

If he's running turbo C++ v3, I don't think he has headers without .h

Sci@phy 97 Posting Whiz in Training

You are calling drawIntersect() two times:
First inside function drawTriangle(), and second time inside main()

Sci@phy 97 Posting Whiz in Training

What is the exact error?

Sci@phy 97 Posting Whiz in Training

I need a house, new car, and a yacht too.

Why do you need the code? And have you tried it yourself?

Sci@phy 97 Posting Whiz in Training

I believe you don't understand exactly process of "overloading" operators.
You can really type whatever you want to do. It's just like a function. If you wish, it can print stuff on the screen.
So the question is: what do you want it to do?

Yet better, how do you want to use it?

Sci@phy 97 Posting Whiz in Training

Unix has various flags.
It doesn't have to do with makefiles.

Try writing instead of _UNIX:
_unix, unix, _UNIX_, UNIX... etc...

The best thing is: see what compiler are you using, and then look at its documentation, because compilers are setting those flags, and different compilers name different names (for exactly, or almost, the same thing)

Sci@phy 97 Posting Whiz in Training

Hi Everyone,

I know conio.h is not available in Unix. I want to use getch(). Using curses.h needs causes the screen to clear which I don't want.

I found a code snippet (source : internet) using termios, it works, the thing is I need to press enter/or any other key thrice...

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

int mygetch ( void ) 
{
  int ch;
  struct termios oldt, newt;
  
  tcgetattr ( STDIN_FILENO, &oldt );
  newt = oldt;
  newt.c_lflag &= ~( ICANON | ECHO );
  tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
  ch = getchar();
  tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
  
  return ch;
}

Any help on this would be of great help...

This exact code works for me perfectly

Sci@phy 97 Posting Whiz in Training

OK. Error 1:
offsetchar[2] is actually char.
And strcpy (what_ever) returns string (which is char ptr), so you have char = char*, it can't be

Error 2:
You have definition of that function:

int charToIntArrays(unsigned char ch[]);

It takes array of unsigned char's, and in main you call:

charToIntArrays(offsetchar[3]);

So you are providing it with only char, and not char*.

Basically, what is your offsetchar? maybe it should be array of strings? But string is already an array of chars, so maybe you should make offsetchar a matrix? (2D array)
I haven't read the whole code so I can't help you more, but I believe this is enough

Sci@phy 97 Posting Whiz in Training
offsetchar[3] = strcpy((char*)&(somepacket.myHeader.offset[0]), "123");

If you define "char offsetchar[3]", then it contains:
offsetchar[0], offsetchar[1], offsetchar[2], not 3!

And that's also reason for second line too

Sci@phy 97 Posting Whiz in Training

Two problems that I see.
What about your input code? First you ask user to insert "a and n", but using scanf() you first get n, then a. That could be problem.

And on end of int main() add return 0;

Sci@phy 97 Posting Whiz in Training

He could always use:

Contestant *c = new Contestant(arg1, arg2);

BOTTOM LINE IS:
Don't allocate dynamically unless you need to.
And you need to do it if you don't know (for example) number of contestors.
But even then, you could make a vector<Contestant> to store all of them

Sci@phy 97 Posting Whiz in Training

Post entire code please. Once more :)

Sci@phy 97 Posting Whiz in Training
typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{	
	Vec1 Row; 
	for( int i = 0; i < 1000; i++ )
	{
                Row.Add("0");
         }
         
          List1.Add(Row);
}

List1[3][3] = "Hello";

It should be something like this :)

Sci@phy 97 Posting Whiz in Training

There's no point in asking "which loop do I HAVE to use."

Every loop does the same thing. You can try it yourself: write something with for-loop, then try to write same thing with other two loops.

Sci@phy 97 Posting Whiz in Training

And what have you done so far? :)

It's rather interesting:
n!/(x!*(n-x)!) different combinations, where n is size of string typed, and x is size of output strings

Sci@phy 97 Posting Whiz in Training

Well, it says about 'n' not being initialised. Try to debug it yourself!

Sci@phy 97 Posting Whiz in Training

On line 7 you have:

int power (int n); // function prototype

And later you call your function:

float power(float a, int n)
Sci@phy 97 Posting Whiz in Training

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

typedef vector<string> row;

vector<row> *vec1 = new vector<row>;
Sci@phy 97 Posting Whiz in Training

Yeah, that's what I would tell you :) Nice job

Sci@phy 97 Posting Whiz in Training

I belive it stores array of strings (all read froom same line, but separated with Delimiter), but am not sure. Try it

Sci@phy 97 Posting Whiz in Training

Isn't negative factorial kind of wrong altogether?

Sci@phy 97 Posting Whiz in Training

Found this using google: Example

1  
   2    private void ImportCountries()
   3    {
   4      string delimiter = ",";
   5      string fileName = @"c:\countrylist3.csv";
   6  
   7      StreamReader sr = new StreamReader(fileName);
   8  
   9      try
  10      {
  11        while (sr.Peek() >= 0)
  12        {
  13          string r = sr.ReadLine();
  14          string[] items = r.Split(delimiter.ToCharArray());
  15        }
  16      }
  17      finally
  18      {
  19        sr.Close();
  20      }
  21    }
  22
Sci@phy 97 Posting Whiz in Training

fflush should not work with input stream!
But in some compilers it does!
That's all

Sci@phy 97 Posting Whiz in Training

You can't type "tree *root". Tree is instance of object, not object.
binaryTreeType<elemType> - this is your class that contains entire tree? Then it should have inside it:

nodeType *root;

And when it is initialised (write constructor for object) root = NULL;
Then inside insert() function, check if(root == NULL) root = &temp; that's how you will initialise root

Sci@phy 97 Posting Whiz in Training

There is at least one problem :)
Some computers have softwares called antiviruses. They could stop your "unnoticed" program to run.
And running a program as soon as portable storage device is plugged in, you will need "autorun.ini" file. It has special code. google it

Sci@phy 97 Posting Whiz in Training

I don't see a problem. You don't need this piece of code:

{
int old_number= 0;
int current_number = 1;
int next_number;

}
Sci@phy 97 Posting Whiz in Training

>If yes, well, you could start with c++
I guess it's a good thing C++ was invented, otherwise all C programmers still would be at a loss of what to do after learning basic data structures. :icon_rolleyes: Do you really only think of C as a path to C++?

I'm amateur on programming thing, and I really don't know reasons why is C better than C++.
But hey, I'm not saying that what I say is always 100% true.
As far as I know, on C++ you can implement every C library if you need, and as a plus, you can use C++ libraries.
For a hobist like I am, I'm more fond of C++ because of std::string, std::vector, and other simplifications that you don't have in C. Still, I believe you have to know how to work without them too.
But never meant to disrespect C programmers.

Sci@phy 97 Posting Whiz in Training

I don't know. What do you know in c?
I started (and still am) as a hobbie programmer, and I learned stuff mostly on internet and e-books.
I'm not a good PROGRAMMER, because to be programmer you have to really be one.

But here's something for you:
do you know what are lists?
Binary trees?
If not, check that out. If yes, well, you could start with c++ :D

Sci@phy 97 Posting Whiz in Training

It's a bad habbit to mix "cin>>" and getline().
The thing is: when you call cin>>, he gets what you need (in this example, char), but leaves everything else (including newline '\n').
And then when getline is called, it just picks up '\n' and stops.
Before calling getline, add this:

cin.ignore(80, '\n');
Sci@phy 97 Posting Whiz in Training

Here's what you have to do:

# include<iostream>

using namespace std;

int main()
{
    int i;
    
    cout << "Please enter the size of square: ";
    cin >> i;
   for(int col=0; col<i; col++) 
   {    
       cout <<endl<<endl;
       
       for(int row=0; row<i; row++)
           {
             if((col==0 || col==i-1) || (row==0) || (row ==i-1))  
             {                                                              
               cout << " * ";
             }
             else cout<<"   ";
               
           }
   }
    system("pause");
    return 0;
    
}

First, notice my for-loops (row and col, both start from 0, not 1)
It doesn't affect program, but it's the more "normal" way in c++ :)

Second, what was your problem:
you didn't have else condition. Then, when if failed, nothing happened.
But now if "if" fails, a blank space is typed.
HTH

Sci@phy 97 Posting Whiz in Training

What did you do so far?

Sci@phy 97 Posting Whiz in Training

You need root pointer that will point at root node inside main fnc. And then call:
tree.swapSubtreeNodes(root);

Sci@phy 97 Posting Whiz in Training

I don't see why there should be any difference. When you write:

void MyClass Func (const MyClass f)
//or even simply:
const MyClass f(some_MyClass_obj);

And let's say we call Func:

Func(some_other_MyClass_obj);

What happens? First let's see what happens in a function:
1. We put in a Func "some_other_MyClass_obj".
2. Program calls constructor to construct "f", a local object inside Func
3. Constructor is checking what are you giving to him. He is checking if "some_other_MyClass_obj" is of type const MyClass or simply MyClass, and then calls proper constructor function.
He doesn't care about line "const MyClass f", because after the "f" is constructed, it will be given const-ness.
4. f is made, and is given his const-ness.


OK, what happens in your recent functions, I'll try to explain.
You have a member function doSomething. That function takes MyClass as argument, and it can change it.
Of course you get error when you try to change f inside your non-member function, that's because f is const! But the important thing is that the const-ness is given AFTER constructor (it's obvious, because constructor HAS to change object!)
And the only thing that distincts your two constructors (for post before) is that one accepts one type of argument, and the other one accepts other type of argument.

VernonDozier commented: helpful +7
Sci@phy 97 Posting Whiz in Training
int return1 (int n);

Why is that semicolon there??? Delete that! Syntax error

ssharish

And why is it called return1??? It should be fact!!!

Sci@phy 97 Posting Whiz in Training

Ok, I have an idea, but am not sure 100%.

When you write:

void Func (const MyClass g)

You say to compiler: MyClass g (I changed a name from f, but it's irrelevant) will not change!

But, that const keyword is irrelevant of calling constructor.
When you write:

MyClass (const MyClass& f)

You say to compiler: This constructor is going to GET object of type: const MyClass!

When you write inside a main function:

MyClass a(3);
const MyClass b(a);
MyClass c(a);

Func(3); //you are calling int constructor that will create const MyClass g(3)
Func(b); //you are calling const constructor, that will create const MyClass g(b) because b is const
Func(c); //you are calling non-const constructor that will create const MyClass g(c) because c is non-const!
Sci@phy 97 Posting Whiz in Training

This is actually very interesting. Well, first thing, i managed to call const constructor by doing this to main:

int main ()
{
    const MyClass f(4);
    cout << "In main before Func call: f.x = " << f.x << endl;
    Func (f);
    cout << "In main after Func call: f.x = " << f.x << endl;
    cin.get();
    return 0;
}

So, if u pass const object to Func, it will obviously trigger const constructor.

I'll post if i find out something new :)

Sci@phy 97 Posting Whiz in Training

I presume h is a pointer to the first node? Like:
NODE* h;

In that case, this code:

if(*h==NULL)
//should be:
if (h == NULL)

Because (*h) is actualy the node itself, and not a pointer.

Sci@phy 97 Posting Whiz in Training

It's not too hard, although a bit tricky. You have to print first line:
1 1 1, then tabb it, then 3 3 3, then tabb it, then 4 4 4 and then go into newline.

In second row instead of tabbing, you add signs + and =, and third row is the same as first. Try it

Sci@phy 97 Posting Whiz in Training

The code is horrible. You still have a lot to learn.
But first:

float calculate_mile_per_hour(float miles, float minutes) //; there's no semicolon here!!!
{
float mile_per_hour;
miles_per_hour = (miles * 60)/minutes);

return (mile per hour);
}
Sci@phy 97 Posting Whiz in Training

You can't put them in the same for-loop!
(Because then what happens? First A[1,1] is printed, then B[1, 1]...)
You have to write two separate for loops each for it's own matrix

Sci@phy 97 Posting Whiz in Training

I'm a beginner in that area, but would like to learn more. Is there any nice tutorial on the web for Windows OS regarding multithreading?

Sci@phy 97 Posting Whiz in Training

Why is ADD 01011?
Do you have some table or?

Sci@phy 97 Posting Whiz in Training

Line 24. is wrong. It has to be inside for-loop.
Look up for reading files

Sci@phy 97 Posting Whiz in Training

I can't tell you much without any more info.

But just like this:
1. Your .h and .c file need to have the same name
2. In your main function you only include .h file
3. And you have to write:

#include "yourname.h"
//and NOT:
// #include <yourname.h>
Sci@phy 97 Posting Whiz in Training

See if you can use vector::get_allocator()
I'm not sure if it would work, but try it

Sci@phy 97 Posting Whiz in Training

A class should contain only one complex number, not two!
You didn't put default constructor in code.
...
The code is full of errors

Sci@phy 97 Posting Whiz in Training

Yes, you can, it is called recursion. Look it up on net

Sci@phy 97 Posting Whiz in Training
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
    
        int getch(){
            struct termios oldt,
                           newt;
            int ch;
            tcgetattr( STDIN_FILENO, &oldt );
            newt = oldt;
            newt.c_lflag &= ~( ICANON | ECHO );
            tcsetattr( STDIN_FILENO, TCSANOW, &newt );
            ch = getchar();
            tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
              
            return ch;
        }

It works for me. Enjoy ;)

Sci@phy 97 Posting Whiz in Training

Also, I believe '//' comments are not allowed