Need Help On C++ - It's my first assignment

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

Need Help On C++ - It's my first assignment

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.

Reply

switch
you can use the 'sizeof' command to determine the size of a variable. I'm not sure if it's in bits or bytes (probably bytes) but there are 8 bits for every byte. As for input and output, there's heaps of basic tutorials around that'll get you what you need. Here's a good place to start: http://www.cprogramming.com/tutorial/lesson1.html.

Good Luck! biggrin.gif

Reply

saga
#include <float.h>
#include <limit.h>

this two header contains the values;


char CHAR_MIN, CHAR_MAX
int minimum = INT_MIN, maximum = INT_MAX
long LONG_MIN or LNG_MIN i forgot...
LONG_MAX or LNG_MAX
float FLT_MIN, FLT_MAX
double DBL_MIN, DBL_MAX


heres how to use this constants in c++ style

CODE
#include <limit.h>
#include <iostream>

void main()
{
cout << "INTEGER MINIMUM = " << INT_MIN << " INTEGER MAXIMUM = " << INT_MAX;
}


this simple code will display the minimum and maximum value an integer can hold and don't be startled if long and int will have the same value smile.gif since most implementation uses 4 bytes for long and 4 bytes for int. If you want the 2 bytes integer.. use the short


to prompt user use this code

CODE
int number;

cout << "enter number: ";
cin >> number;
count << endl << "the number u entered is " << number;



i hope this helps.. if not smile.gif

 

 

 


Reply

seanooi
i cam up with something like this:

CODE

#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 << endl;

int number;

cout << "Enter number: ";
cin >> number;
cout << endl << "The number u entered is " << number;
cin.get();
cin.get();

return 0;
}


But I'm not sure if it complies with what my lecturer wants, so can someone please check it out for me? biggrin.gif

Reply

seanooi
OK, this is what I got now, and i'm pretty sure that this is what the assignment is suppose to be like. Hope that someone will look it over for me and tell me if i'm doingmething wrong here biggrin.gif
This is just the code for listing the data types.

CODE

#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

int main()
{
cout << "bool\t" << sizeof(bool)*8 << "\t" << 0 << "\t" << 1 << endl;
cout << "char\t" << sizeof(char)*8 << "\t" << CHAR_MIN << "\t" << CHAR_MAX << endl;
cout << "short\t" << sizeof(short)*8 << "\t" << SHRT_MIN << "\t" << SHRT_MAX << endl;
cout << "int\t" << sizeof(int)*8 << "\t" << INT_MIN << "\t" << INT_MAX << endl;
cout << "long\t" << sizeof(long)*8 << "\t" << LONG_MIN << "\t" << LONG_MAX << endl;
cout << "float\t" << sizeof(float)*8 << "\t" << FLT_MIN << "\t" << FLT_MAX << endl;
cout << "double\t" << sizeof(double)*8 << "\t" << DBL_MIN << "\t" << DBL_MAX << endl;
cout << "double long\t" << sizeof(double long)*8 << "\t" << LDBL_MIN << "\t" << LDBL_MAX << endl;

cin.get();
cin.get();

return 0;
}

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. cout long numbers c - 32.02 hr back. (1)
  2. c double max int_max - 46.84 hr back. (1)
  3. long_max limit.h - 51.00 hr back. (2)
  4. limit.h c header max() - 64.41 hr back. (1)
  5. c limit.h - 80.05 hr back. (1)
  6. char_bit limit.h - 81.12 hr back. (1)
  7. limit.h max int - 87.82 hr back. (1)
  8. int_min and int_max c header? - 98.64 hr back. (1)
  9. c limit.h - 8.27 hr back. (2)
  10. limit.h dbl_max - 112.24 hr back. (1)
  11. c limit.h header - 131.97 hr back. (2)
  12. what is the c program for displaying minimum and maximum values of acepted integer inputs - 132.75 hr back. (1)
  13. limit.h c max int - 139.37 hr back. (1)
  14. dbl_min c - 141.86 hr back. (1)
Similar Topics

Keywords : c, assignment

  1. University Assignment Help
    database aplication in c++ (7)


      Looking for c, assignment

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for c, assignment

*MORE FROM TRAP17.COM*
advertisement



Need Help On C++ - It's my first assignment



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE