FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


C++ assignment help





seanooi
well guys, I'm very new to C++, and I've just received my new assignment today but don't know what does it mean, so I was hoping that you could help me out with it.

In my assignment, I'm required to write a program that does the following.
- It first lists each of the basic data types, stating the number of bits they use, their min and max values, and for floating point types, their min and max exponent values.
- Then have the program prompt the user to enter a number and reply stating what number the user entered.
- Must be presented all output to the user in a nice, userfriendly manner.

My lecturer said something about do not hard code it out at the end of the class.
wowz
That sounds easy Smile
I can probably write it for you.. for a price Wink FRI$$$$
I'm sure you can persuade others to do it too Surprised
If you just want help writting it, send me a pm and I'll see what I can do for you.
Or, I can write it and leave notes so you can figure out what I did
Pick what you want and pm me or make another post advertising that you will pay FRI$ for c++ writting
djclue917
The program is very easy indeed. You should try programming it to hone your skills. Anyways, I'll just give you the data...



You could also try to copy the whole table. Just omit the enum, unsigned *, long *, and short int data types.

By the way, you could find out the length of a data type by using the sizeof() operator (take note, it's an operator, not a function). The sizeof() operator will return the data type's length in bytes. The length of the data types may vary from compiler to compiler (and settings).

In Microsoft Visual C++, the length of an int is 32 bits... However, when you use G++ (GNU C++ Compiler), the length of an int is 16 bits.. You should follow the data I gave.

Example:

cout << sizeof(int); // outputs to the console the length of data type int

Hope that helps...
Learning C++ is really fun you know... Smile
seanooi
I'm grateful for your help, but I must admit that I am really dumb at all these as I've just been to two classes.
Just a quick question, what library should I use? iostream and climits?
dac_nip
That's very easy. It's basic, you need to know it yourself in order to survive for the next days of your lesson. Try read the book on data types, just be patient. Very Happy
djclue917
seanooi wrote:
I'm grateful for your help, but I must admit that I am really dumb at all these as I've just been to two classes.
Just a quick question, what library should I use? iostream and climits?


It really depends.. Well basically, you need iostream for the very basic cin and cout.

You could just cout the whole table just like that. Smile
Anyways, if your professor has a certain requirement/rule to it, be sure to stick to that requirement/rule.

Hope that helps...

Remember: Read, read, read.... And read some more. You just need to have the initiative to learn and you'll be good at C++ programming in no time.
Zuwiki
I'm no C++ expert, so I don't know much about it, but I think there is a way to list how many bytes are in a memory location, so theoretically, you could just make one of each variable type with max value (or maybe minimum, i dont know) and use that command to list the bytes.

Or you could just do a cout with all the information in it. That seems kind of boring...

Where are you taking the class anyway? I wouldn't mind learning C++, but my ADD won't let me read books Very Happy , so a class sounds good.
djclue917
Zuwiki wrote:
I'm no C++ expert, so I don't know much about it, but I think there is a way to list how many bytes are in a memory location, so theoretically, you could just make one of each variable type with max value (or maybe minimum, i dont know) and use that command to list the bytes.


Actually there is a C/C++ operator which can return the number of bytes used by a certain data type, not a specific variable because all variables of the same type have the same length. The sizeof operator is capable of doing that. For example, if you want to print to the screen the number of bytes of the data type int, you could do this:

cout << sizeof(int);

for char:

cout << sizeof(char);

and so on...

Just remember that the output of these is not fixed. It means that the length of a certain variable of a certain data type might vary from system so system and compiler to compiler.

Hope that helps...
MonkeyWrench
oh jeez, all this is complicated;

// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}



Hello World!

The first panel shows the source code for our first program. The second one shows the result of the program once compiled and executed. The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program.

The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written:

// my first program in C++
This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.
#include <iostream>
Lines beginning with a pound sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.
using namespace std;
All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.
int main ()
This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before of after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function.

The word main is followed in the code by a pair of parentheses (()). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them.

Right after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed.
cout << "Hello World";
This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.

cout represents the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (which usually is the screen).

cout is declared in the iostream standard file within the std namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code.

Notice that the statement ends with a semicolon character (Wink. This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).
return 0;
The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code 0). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ program.
vignesh_natraj
Actuallt C++ is similar to C .If you are comfortable with C then learning C++ would be really fun and easy.C++ is a super set of C with some improved features like classes,data protection,etc.
seanooi
ok, i think i've done something but i'm not sure if it's what my lecturer wants, so just wanted you guys to help me take a look at it please Very Happy

This is my source:
Quote:

#include <iostream>
#include <climits>

using namespace std;

int main()
{
int n_int = INT_MAX;
short n_short = SHRT_MAX;
long n_long = LONG_MAX;

cout << "int is " << sizeof (int) << "bytes. " << endl;
cout << "short is " << sizeof n_short << "bytes. " << endl;
cout << "long is " << sizeof n_long << "bytes. " << endl;

cout << "Maximum values:" << endl;
cout << "int: " << n_int << endl;
cout << "short: " << n_short << endl;
cout << "long: " << n_long << endl;

cout << "Minimum int value = " << INT_MIN << endl;
cout << "Bits per byte = " << CHAR_BIT << endl;

cin.get();

return 0;
}


This is the output:
Quote:

int is 4bytes.
short is 2bytes.
long is 4bytes.
Maximum values:
int: 2147483647
short: 32767
long: 2147483647
Minimum int value = -2147483648
Bits per byte = 8
tsylvest
wowz wrote:
That sounds easy Smile
I can probably write it for you.. for a price Wink FRI$$$$
I'm sure you can persuade others to do it too Surprised
If you just want help writting it, send me a pm and I'll see what I can do for you.
Or, I can write it and leave notes so you can figure out what I did
Pick what you want and pm me or make another post advertising that you will pay FRI$ for c++ writting


I'd suggest writing it on your own. You will get nowhere by having other write your code for you. I've seen so many people fail out by either doing this, or copying code. Programming is all about spending many hours figuring out how to accomplish a goal, then spending many hours debugging your work. Just keep with it, and it will all be worth it. And ask questions when needed.
Related topics
HELP ME in C++
Need help in Borland C++ 3.0
help with school assignment
C++ code help
C++ Assignment! its about string.h
C&C: Generals Help
Code::Blocks C++ IDE Help !
Any teenage webmasters out there?
what function gives process id in C#
Ive Got the FLU
WinSit.exe being called everytime XP starts
Basic C Programming Help?
Best cure for a common cold?
How to tackle snowfall--please suggest
Reply to topic    Frihost Forum Index -> Computers -> Computer Problems and Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.