tux4life 2,072 Postaholic

Hey Gretty, your program containing that class won't compile for these reasons:

  • void attributes(int, string, string); -> where is the code for that function?
  • dog.attributes(2,jim,kkjkjk); ,
    you probably meant: dog.attributes(2,[B]"[/B]jim[B]"[/B],[B]"[/B]kkjkjk[B]"[/B]); -> notice the quotes.

    If you write it without quotes, then the compiler assumes that jim and kkjkjk are variables/instances of the string class.
    But I'm pretty much sure that you meant to wrap it between quotes :)

tux4life 2,072 Postaholic

Edit:: Direct after replying I noticed the date of the last post.
Edit:: However, this might still be a useful advice for anyone who reads the thread.

Bad coding practices!

  1. !fin.eof() Check out this.
  2. system("pause"); Check out this.
    You could use cin.get() as a replacement.
  3. return 1; Why would you want to return value 1 if your program has terminated correctly?
    Make it return 0;

:)

tux4life 2,072 Postaholic

>Well, now you know how it feels to get negative rep
Are you implying that you gave him bad rep only for giving someone bad rep?
BTW, Do you really think he's crying for getting 1 point bad rep?
He only doesn't find it nice if you give him bad rep, without any real reason (like anyone does).

tux4life 2,072 Postaholic

Ok, thank you all

Heh, according to your profile you hate the ":D" smiley:

P.S. I hate the ":D" smiley and prefer the ":)"

and now you're using it ?

:P

tux4life 2,072 Postaholic

>i was just wondering if they were a key feature of the language
Yes, otherwise you now weren't talking about it. Edit:: It's at least a feature;

>something that should be taken advantage of
Look at Tom Gunn's post :)

tux4life 2,072 Postaholic

Just few quick question:

How often are pointers to functions used? Should i implement them in my programs?

To be honest I have never had to use them up until now.
You should only implement something in your program if there's need to, it's not because you've the possibility to do something, that you actually have to do that "something" as well eh?

:P

athlon32 commented: Thanks :D +1
tux4life 2,072 Postaholic

And if you only want the file names then use:

dir /b > files.txt

:)

Edit:: You can also combine this one, with sknake's one:

dir /b /s > files.txt
tux4life 2,072 Postaholic

tux4life, I challenge you to write the same program with the same features and restrictions and show me how it's so much better than mirfan00's that he deserved all of that harassment. You're quick to mouth off, but can you back it up with your own perfection?


The only old style header is <string.h>, and even though it's officially deprecated, it's not going away any time soon because then compatibility with C would go out the window.

There's no way to replace typed characters with a star using standard code. To do that you have to use something that isn't portable, and conio is as good a choice as any for a toy program.

Only 3 lines out of over 40 are commented out. I didn't get good grades in grade school math classes, but I'm pretty sure 3 isn't even close to half of 40.

You forgot to say that <string> should be included because the code uses the standard C++ string class. And you forgot to say that '\r' is a portable replacement for 13. For all the complaining about old style headers, you forgot to say that the only code using them is commented out so both can be removed. I see you complaining about the same things over and over, and ignoring other things that are in the same league or worse. It kind of makes me think that you don't really know what you're talking about and just copy people who do.

Well, …

tux4life 2,072 Postaholic

Could you please post using code tags?
Information about code-tags is posted all over the website :

1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in

>Is there a way of Increasing the size of tmp so that it can handle very large integers ..
Yes, use a big-number library like: "GNU MP Bignum Library"

tux4life 2,072 Postaholic

And...Don't use void main!!, migrate your code to conform to the C++ standard: http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html :)

tux4life 2,072 Postaholic

I found this snippit a while ago that isolates all words using a vector

not my code:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Returns true if text contains ch
inline bool TextContains(char *text, char ch) {
	while ( *text ) {
		if ( *text++ == ch )
			return true;
	}

	return false;
}

void Split(char *text, char *delims, vector<string> &words) {
	int beg;
	for (int i = 0; text[i]; ++i) {

		// While the current char is a delimiter, inc i
		while ( text[i] && TextContains(delims, text[i]) )
			++i;

		// Beginning of word
		beg = i;

		// Continue until end of word is reached
		while ( text[i] && !TextContains(delims, text[i]) )
			++i;

		// Add word to vector
		words.push_back( string(&text[beg], &text[i]) );
	}
}

int main() {
	vector<string> words;

	// Split up words
	Split( "Hello, my name is william!", " ,!", words );

	// Display each word on a new line
	for (size_t i = 0; i < words.size(); ++i)
		cout << words[i] << '\n';

	cin.ignore();
}

Hey, you don't have to copy-paste the whole code, please just provide a link instead: http://www.daniweb.com/code/snippet1068.html :P

tux4life 2,072 Postaholic

Classes are often used in very large projects, it's another approach of programming.
Classes are also commonly used to implement new datatypes.

Hey crash1989, could you please post using code tags?

tux4life 2,072 Postaholic

Struct(ure):
In C++ you could say that a struct is also a sort of class, but when someone uses the struct keyword, he's often just referring to a structure as (POD = Plain Old Datatype), POD means that it's used as they did before in C: a structure is used to group (related) variables (they don't necessarily have to be of a different type)

example:

struct book
{
  char author[20];
  char title[30];
  double price;
};

Class:
A class is used to encapsulate data, it allows you to implement Object Oriented design into your program, a class can have three access specifiers: public, private and protected: In a class, all data is private by default, this means that you cannot access it directly and that you'll have to implement a method (= another name used for 'function' when we're talking about classes) if you want to make your data accessible.
public on the other hand means that you allow your data to be accessible, and protected means that your data is only accessible for methods of the class or for inherited classes from that class.
Remark: In C++ a structure is also a class (but in a structure is all data public by default)

example:

class fish
{
// everything here is private
public:
  void swim() { cout << "Swimming..." << endl; }
  void eat() {cout << "Eating..." << endl; }
};

Enum(eration)
An enumeration is what the name says: an enumeration (of …

tux4life 2,072 Postaholic

>for(int i = 0; i < 5; i++)

That code where 'i' is declared with the parenthesis
...
'for' loop initial declaration used outside C99 mode JFYI

I didn't notice I was in the C forum, but according to C99 this was valid, however I edited my post to conform to the C89 standard :)

C89:

int i; // declare this variable before any statement in your code
for(i = 0; i < 5; i++)
{
  /* The code in this code block will run five times */
}

C99:

for(int i = 0; i < 5; i++)
{
  /* The code in this code block will run five times */
}
tux4life 2,072 Postaholic

Could you post down your code (please use code tags) and the contents of the file as well?

tux4life 2,072 Postaholic

i need another solution for for looping

Changing it to a for loop is not that difficult, look up how a for loop works, or take a look at this small example:

int i; // declare this variable before any statement in your code
for(i = 0; i < 5; i++)
{
  /* The code in this code block will run five times */
}

And because you're so kind I've also Googled up a tutorial about Control structures (if, while, do-while, for): http://www.cplusplus.com/doc/tutorial/control/ :)

tux4life 2,072 Postaholic

It can. If you do not initialize it, it can contain the last value a variable of that type had. Uninitialized variables can go do any memory slot, regardless of whether the slots are vacant or not ;)

Wrong!

If you're talking about C-strings, in other words: character arrays, then it can contain garbage if you don't initialize it.
When talking about C++ strings you don't have to initialize it, your string doesn't contain garbage when you don't initialize it.

Consider the following examples:

// Using a C-string
char cstring[50];
cout << cstring << endl; // garbage in most of the times
// Using a C++ string
string cppstring;
cout << cppstring << endl; // won't print garbage on your screen
tux4life 2,072 Postaholic

Don't use conio ( #include<conio.h> ), it's unportable!
To the OP: Are you encountering any problems with your current code? (as you only posted your new code)

tux4life 2,072 Postaholic

>is there anyone who could help.
thankss very much. this is due on 7th July .

Seems like someone is thinking that we will do it for him.

Could you maybe first post what you have so far?

Edit:: If you had searched the forums before posting your homework assignment, then you would have found a thread (a recent one) which addresses a very similar problem:
http://www.daniweb.com/forums/thread198519.html :)

tux4life 2,072 Postaholic

So , it is possible to writ this :

enum 
{ 
    A,    // A == 0
    B,    // B == 1
    C=100, // C == 100
    D=20, // D == 20
    E,    // E == 21
    F     // F == 22
};

Well, what has Tom Gunn just said?
Apply that to your example and you'll know :)

tux4life 2,072 Postaholic

>There's plenty of big-number libraries on the net, or if you have the programming ability, you can write your own big-number class.
Huh? A class in C ??

:P

tux4life 2,072 Postaholic

This program is real rubbish, old style headers, conio, half of the code is commented out, system("pause") (don't use it), etc...
My recommendation is: migrate to standard C++ first, they really should make it a forum rule...

BTW, Does it really hurt you to use code tags:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in

(as already discovered by valinux):
If you still really want to fix your code, then you should add a check before adding the character to the variable, otherwise there will be an ENTER in the pass-string where you compare the real password to, always resulting in a Non Confirmed message, a simple check might look like this: if( a != 13 ) pass += a; :)

tux4life 2,072 Postaholic

Well, I have a very strange problem with my laptop: sometimes it wants to boot and sometimes it doesn't want to boot.
First of all, I want to specify what I mean with doesn't want to boot:
If I press the power button of my laptop, then the LEDs of my wireless network card and battery are on, however, the three lights on top of my keyboard (indicating CAPS-LOCK, NUM-LOCK, etc...) don't light up.
I've already removed the Hard disk, but with no success, so the problem isn't related to my harddrive, I also tried replacing it by another one, but again: no success.
Now I'm thinking that it's probably the RAM memory, or do you have any other ideas?

Recently I could get it booted, (when it wants to boot, the LEDs of my keyboard are on, otherwise not, when it doesn't boot, the display doesn't work as well and I'm not receiving any beeps from my laptop): I booted my laptop from an Ubuntu Live-CD, well it booted, I could move the mouse and enter things on my keyboard, but after a while it seems like everything is frozen (moving the mouse doesn't work, the keyboard doesn't work anymore, external USB-mouse doesn't work as well, I didn't face this problem only on this live-cd, I only had it in the beginning (when the problem begun), when the harddisk was still in my laptop and when Windows was booting fine, it just hung at …

tux4life 2,072 Postaholic

I'm not even going to bother trying to understand that code, but it's full of small bugs such as this:

if(number[i] [B]=[/B] pi || number[i] == PI || number[i] == Pi || number[i] == pI)

Not to mention the entire line is pointless anyway.

My advice for you is to start over, read a tutorial or book on C++, and scrap this code.

Agreed, but one thing has definitely to be pointed out: never use floating point comparisons in your program, never!
(you might want to check this)

And instead of including stdio.h, you should include cstdio (the new-style header): #include <cstdio> :)

tux4life 2,072 Postaholic

The GNU MP Bignum library is a very good one :)

tux4life 2,072 Postaholic

Add '*' and change it to void and then it should work:

[B]void[/B] increase(int [B]*[/B]a, int [B]*[/B]b) {
  [B]([/B]*a[B])[/B]++;
  [B]([/B]*b[B])[/B]++;
}

:)

tux4life 2,072 Postaholic

A quick guide on passing variables by reference, using pointers

Consider this function:

void padd(int *p, int b)  // create a pointer to an integer variable (parameter)
{
    *p += b;  // add the value in 'b' to the number
}

You'll have to use the function like this:

int var = 3;
padd(&var, 5); // pass the variable by reference

printf("%d\n", var); // will print '8' on the screen

Hope this helps :)

tux4life 2,072 Postaholic

So, what's stopping you from marking this thread as solved?

tux4life 2,072 Postaholic

You could easily use a loop for things like this:

cin >> Number[0];
cin >> Number[1];
cin >> Number[3];
cin >> Number[4];
cin >> Number[5];
cin >> Number[6];
cin >> Number[7];
cin >> Number[8];
cin >> Number[9];
cin >> Number[10];
cin >> Number[11];
cin >> Number[13];
cin >> Number[13];
cin >> Number[14];
cin >> Number[15];

is replaceable by:

for(int i = 0; i < 16; i++)
  cin >> Number[i];

Edit:: Please keep in mind that Number is a character array, this means that if you enter an integer number, that it will be converted into it's ASCII equivalent, for example if you enter 65, it will be converted into A ...
Edit2:: time.h is an old-style header, replace it by ctime, so the include statement would become: #include <ctime>

tux4life 2,072 Postaholic

Smart trick, using two different accounts to post the same question across multiple forums on Daniweb:
http://www.daniweb.com/forums/thread199505.html
http://www.daniweb.com/forums/thread199506.html
Congratulations! You've just decreased you own chances of being helped by the people here :)

VernonDozier commented: Death to multiple posters! +17
tux4life 2,072 Postaholic

28 Posts, and no code tags??

Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in.

BTW, Where in your code are you making use of the conio library? If there's no need to use it, then don't use it, it's even not portable as well.

>output is -100.000 how is it possible??

float s=10,u=30,t=2,a;
a=2*(s[B]-u*t[/B])/squ(t);

In your code: u multiplied by t is greater than s, so if you subtract u*t from s then it's logical that the result is a negative number right?
(this is strictly according to the rules of algebra)

tux4life 2,072 Postaholic

>what does this mean ! we can not give "value1" a value more than "value2" ?
You even didn't take a look at the link in siddhant3s' post, what a shame!

tux4life 2,072 Postaholic

Well, normally if you want to make sure that your program is platform independent, pdcurses is often used for that :)

tux4life 2,072 Postaholic

I have to ask myself; am I really interested in the posts of members who can't tell the difference between code and text.

What are you trying to achieve with that?
I know: You don't want to be helped.
(Even if you 'formatted' your code in italic, it's very annoying to read, just wrap it in between code tags)

tux4life 2,072 Postaholic

Normally code is wrapped between code tags, learn how to use them and increase your chances of being helped by the forum members :)

tux4life 2,072 Postaholic

Define 'LARGE', 1GB, 2GB, 10GB, 100GB ??
If it's for example 4GB, then you already need a computer with bunches of RAM, to read the whole file into a character array :P
As already mentioned: The buffer technique is the solution for this, try it out :)
When you've put together some code, you can post it down here, so we can take a look at it and see what advices we can give you to improve your code...

tux4life 2,072 Postaholic

Why not using a stringstream ?

unsigned char arr[] = "4564";
unsigned int val = 0;
    
stringstream ss;
ss << arr; // write the array to the stringstream
val = ss.get() - '0'; // get next digit and store it in 'val'

This is only an example, you'll have to adapt it to your needs, if you want to get the next digit, then you just invoke [B]val = ss.get() - '0';[/B] .

Hope this helps!

REMARKS:

  • If you're using stringstreams in your code, then you'll have to include the sstream header: #include <sstream> .
  • Also this example doesn't provide checking to see whether the end of the number has already been reached.
  • Getting the whole number is even easier: ss >> val;
tux4life 2,072 Postaholic

>Memory is deleting here???...what is happening....?
Well, my eyesight is not good enough to see your code from here :P
Could you post it please?

Sky Diploma commented: Lol! +4
tux4life 2,072 Postaholic

To the OP: Take a look at VernonDozier's post, it will help you much, one thing to mention is that his code will store the number in the reversed way, fro example when you have the following number: 895, it will be stored as "598", there's nothing wrong with this, you only have to take this into account, I say this because otherwise you might not have seen this pitfall and your code would have been wrong from the beginning then :)

tux4life 2,072 Postaholic

Please don't use system("pause") ...
Use cin.get(); instead.
(explanation)

BTW, why are you including windows.h ( #include <windows.h> )? You aren't using anything of it.

:)

tux4life 2,072 Postaholic

Maybe you should check out this as well :)
(But change the void main() to int main() )

tux4life 2,072 Postaholic

ok, being a doctor i don't have a sufficient idea about this problem so help;

Maybe you could start by taking a look at the link in Tom Gunn's post ?
What help do you expect, where are you having problems with?
Don't expect that we'll write the program for you, under no circumstances, but we can always help you with the parts that you find tricky to implement :)

tux4life 2,072 Postaholic

no actually, i have been told that switch can be used easier than array,,,,,,,,,,,
that is ok,

Easier? Are you kidding? No!! Never!!
The problem just gets worse when you have to deal with large numbers like 1475012523 for example...
Wow, and you're going to implement all that using a switch?
Good luck then! I'd be glad to receive a copy of your code when it's finished :P

tux4life 2,072 Postaholic

I will keep that in mind thanks!!! :)

No, don't do it, what he says is wrong...

tux4life 2,072 Postaholic

And here the complaining starts all over: Don't use void main(), it's evil!!
Migrate to standard C++

>but i was unable to display numbers like 365 in words
Well, where do you think the "hundred" will be inserted ?

Why using goto if you can easily use a while loop ?

The problem isn't strange, but your code is incomplete :)

tux4life 2,072 Postaholic

It sure seems that way, because you missed this part in red: (well I marked it in Green, that's a color which doesn't express frustration)

Naturally giving away the answer is a subjective thing, so just make sure that the person you help can't just take your code and turn it in for a grade.

Seems like you're a bit dyslectic (but with sentences): You only read parts BEFORE the comma, if you quote someone's words, then please repeat all his words, not just a part of it, you're just an expert in taking things out of it's context.
And be sure, a moderator will tell it to you (seems like you really want it), you can sleep on both ears...

I say that he can't turn my code in for a grade because it uses two tricks with pointers that a student asking for help on this problem couldn't figure out independently.

Conclusion: You are the number one!!
Are you maybe implying that the OP is too stupid for using Google?
No one is too stupid to just Google up something, you just don't have to be too lazy! (And I'm not trying to blame the OP for this legitimate question)

Edit::

I want to be told by an authority that I'm breaking the rules, not some net nanny who just doesn't like that I'm actually helping instead of bashing people about code tags, "rusty code", and using compilers that are forced on them …

tux4life 2,072 Postaholic

I don't see how that's relevant. The rules I quoted apply to initializer lists with or without designated initializers.


How is that different from saying that when you initialize one element in an initializer list, the rest default to 0? Same concept, different words.

Do you always want to have the last word?
Well then here's your chance, please catch it!
But remember one thing: The last word is not always the best word!

tux4life 2,072 Postaholic

tux4life, most of what I write is for school and I had a professor who had a vendetta against cin.get for some reason so I got into the habit.

Refer him to the link in my previous post then, if he doesn't understand what they're saying there then he might not be a suitable person to be a teacher.

tux4life 2,072 Postaholic

Seems like the OP isn't very interested in being helped?

Salem commented: Strange that, it happens a lot ;) +36
tux4life 2,072 Postaholic

nvm. going to ask teacher.

Are you implying that your teacher knows more than everyone together, here on Daniweb?
:P