GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Mar-2004, 15:09
-MX- -MX- is offline
New Member
 
Join Date: Mar 2004
Posts: 6
-MX- is on a distinguished road
Unhappy

Difference between c and c++ [was:New to C, I need help!]


Hi people,
I am new to programming, and am trying to create a program, but i cant , can anyone help?...
....
Write a program that inputs one five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each.[Hint: use combinations of integer division and modulus.] For example, if the user types in 42193 the program should print:
4 2 1 3 9
...

Looking forward to ur replies...i need it Urgently please...
Peace....-MX-
Last edited by JdS : 12-Mar-2004 at 08:24. Reason: Please use a better title in your thread
  #2  
Old 11-Mar-2004, 15:42
pan pan is offline
New Member
 
Join Date: Mar 2004
Location: Greece
Posts: 16
pan will become famous soon enough

New to C


Hey,

As you may have noticed, if you have read through other posts, this forum is not a do-your-homework-for-you forum, however I can help with specific problems and questions you may have about some code you have at least attempted to write.

In terms of the mathematics of your question, the following piece of code may be able to give you some hints:

CPP / C++ / C Code:
int num = 12345;

while ( num > 0 ){
	int digit = num % 10;
	cout << digit << '\n';
	num = num / 10;
}

Best of,
Pan Thomakos
  #3  
Old 11-Mar-2004, 15:53
-MX- -MX- is offline
New Member
 
Join Date: Mar 2004
Posts: 6
-MX- is on a distinguished road
hey sup pan?...thanx for your help...anyways...is there any difference between c and c++?
  #4  
Old 11-Mar-2004, 16:05
pan pan is offline
New Member
 
Join Date: Mar 2004
Location: Greece
Posts: 16
pan will become famous soon enough

C and C++


Quote:
Originally Posted by -MX-
hey sup pan?...thanx for your help...anyways...is there any difference between c and c++?

Yeah, actually C was developed before C++. C was a "sequential" programming language (i.e. one instruction after another...) Also, C was written to be quite hardware independent, and required some carfeul planning for portability to different systems. Then C++ (then called "C with objects") was developed (approximately 1980), which allowed programmers to create objects (hence object-oriented programming) with data, variables, and functions that could be shared and replicated easily. Objects essentially were reusable software components that modeled real world objects. Today, the most common differences (at a beginner level) between C and C++ deal with file handling and objects. For instance, output in C++ is handled through "cout" and in C it is handled with "fprint". Also, C++ deals more with "class" objects, and C deals with "structs".

Most software is written in either C, C++, or a combination of both.

Let me know if you have any more questions about these.

Best of,
Pan Thomakos
  #5  
Old 11-Mar-2004, 16:16
-MX- -MX- is offline
New Member
 
Join Date: Mar 2004
Posts: 6
-MX- is on a distinguished road
Thank alot for the information, yea, actually, i have another question, i found the answer to my previous question, but it doesn't run in Borland C++...y?..i noticed that it uses cout, instead of prinf, is there really alot of difference between the two?, or are they similar?
  #6  
Old 11-Mar-2004, 16:22
pan pan is offline
New Member
 
Join Date: Mar 2004
Location: Greece
Posts: 16
pan will become famous soon enough

C code


Hey,

Here is the C version of the code:

CPP / C++ / C Code:
#include <stdio.h>

void main(){
	int num = 12345;

	while ( num > 0 ){
		int digit = num % 10;
		printf( "%d\n", digit );
		num = num / 10;
	}
}

Regards,
Pan Thomakos
  #7  
Old 11-Mar-2004, 16:29
-MX- -MX- is offline
New Member
 
Join Date: Mar 2004
Posts: 6
-MX- is on a distinguished road
Thanx alot, now i need you to explain every part of the code you wrote..so i can write my own version ;-)
  #8  
Old 11-Mar-2004, 16:33
pan pan is offline
New Member
 
Join Date: Mar 2004
Location: Greece
Posts: 16
pan will become famous soon enough

explaining


Hey,

The explaining part is for you to figure out, so that you can figure out how to solve your problem. The best way to figure out what code does, is to go through it, line by line. Write down the value of each variable, and perform the operations of each line... You can even include your own print statements, after lines, to see how values have changed.

Best of luck,
Pan Thomakos
  #9  
Old 12-Mar-2004, 01:06
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Pan,
The idea behind these boards is to help people solve their own programming assignments, not to give them the answers. Please do not post working code that is a solution to their problem. They learn nothing, and you don't get the grade for their assginment.

Okay? Thanks.
  #10  
Old 12-Mar-2004, 05:43
pan pan is offline
New Member
 
Join Date: Mar 2004
Location: Greece
Posts: 16
pan will become famous soon enough

Helping and Solving


Hey,

Actually, my code is not a solution to the problem, it just demonstrates the use of the modulus and integer division. It prints the digits in reverse order, and the actual process of printing them in the correct order (mathematically) is fairly different. I am sorry if this is considered posting working code, maybe you could clarify the difference between code that simly demonstrates and code that actually solves the problem.

Thanks,
Pan

P.S: Through a very simple internet search I also found similar code in VB, which also explains what modulus and integer division do:

http://www.faqts.com/knowledge_base/view.phtml/aid/3095
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.