Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Misc > Archive::Off Topic

Archive::Off Topic Archive area for Off Topic's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2004, 10:25 PM
samandhi's Avatar
samandhi
Demi-God
 
Join Date: Aug 2003
Posts: 1,056
Default Another C++ programming question.

I have recently found an AWESOME home/type study course called "The Complete C++ Training Course" and I am totally loving it, as it is by far the best I have seen amoung the combination of home study and beginners guides.... The question I have is because of the following:

At the end of every chapter, there are (what you might expect) exercises to prove that you really paid attention in the reading. They are not as easy (at least so far as I have noticed), as the ones in other books. I am having trouble with the 36th exercise, because I am not totally sure that The question covers something I have learned in that chapter... In all actuallity, the book has yet to go in depth on anything related to C++ language itself (read the syntax), but instead, has covered more about WHAT it is and where it came from, and what OOP and OOD (along with what UML) are..

The reason I am asking this, is because it doesnt have the answers to the questions in the exercises, as they are used in colleges and the like....

The exercise question is this:
Quote:
Write a program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each. (Hint: Use the integer division and modulus operators.) For example, if the user types in 42339 the program should print:

4 2 3 3 9
Now, Im not totally sure that I have enough information (without the knowledge of the language) to do this.. Can someone help me out here and let me know, so I can store it in my brainpan? The idea I have behind this goes back to my reading from "Who's Afraid of C++?", where it talks about how variables are stored in chunks of memory. Each chunk of memory that is tagged as THAT stack for that particular variable has a memory address. I would imagine it is just a matter of telling the computer to print address 1001, then 1002 and so on... But I have no idea how to do this, as I have not reached any kind of syntax that would do that... You'll notice that this thought has NOTHING to do with division and modulous calculations, which is my problem. I guess I am not seeing how they are thinking ( or thinking the way they are), enough to figure this one out.. :(
__________________

Quote:
Analysis paralysis will keep you from failing, but it will also keep you from succeeding.
  • L.L. CoolJ
Reply With Quote
  #2  
Old 03-01-2004, 10:50 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

http://people.uncw.edu/tompkinsj/112...36solution.cpp

// Exercise 1.36 Solution
#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
int num;

cout << "Enter a five-digit number: ";
cin >> num;

cout << num / 10000 << " "; //prints the left most digit (5th)
num = num % 10000; //assigns a new value to num -four digits
cout << num / 1000 << " "; //prints the left most digit (4th)
num = num % 1000; //assigns a new value to num -three digits
cout << num / 100 << " "; //prints the left most digit (3rd)
num = num % 100; //assigns a new value to num -two digits
cout << num / 10 << " "; //prints the left most digit (2nd)
num = num % 10; //assigns a new value to num -one digit
cout << num << endl; //prints the last digit of num and a newline

return 0;
}
Reply With Quote
  #3  
Old 03-01-2004, 11:39 PM
samandhi's Avatar
samandhi
Demi-God
 
Join Date: Aug 2003
Posts: 1,056
Default

Sweet, thank you very much... That was the ONLY one in the exercises that I had any problem with...
__________________

Quote:
Analysis paralysis will keep you from failing, but it will also keep you from succeeding.
  • L.L. CoolJ
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:17 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3