Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 25-07-2006, 12:29 PM   #1 (permalink)
Right Off the Assembly Line
 
aniishvara@gmail.com's Avatar
 
Join Date: May 2006
Posts: 30
Smile a small c problem


i have 2 questions in my book for which i am not able to decide on the exact solution..

? 1- write a program to accept any number upto 6 digits and print that in a string.
Eg:
input number 1034
output string one thousand thirty four
? 2- write a program to accept any date in numbers annd print that in string
Eg
input date: 19/3/96
output string nineteen march ninety six.
aniishvara@gmail.com is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 25-07-2006, 02:51 PM   #2 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: a small c problem

Since it's probably a homework question, I'm not going to give the answer as code.

In both, you need to extract the digits one by one, and display accordingly.

Use a loop to extract the digits, and store them in variables. Then output them after the loop has finished.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 25-07-2006, 03:56 PM   #3 (permalink)
In The Zone
 
nik_for_you's Avatar
 
Join Date: Apr 2004
Location: Paris
Posts: 313
Default Re: a small c problem

use of arrays,pointers will help you .. had done both programs in past.. try it own dear
__________________
I AM REBEL
nik_for_you is offline  
Old 25-07-2006, 05:15 PM   #4 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: a small c problem

I am glad you guys didn't give out the code This surely is a homework problem! Solve it on your own man! These guys have given you enough hints!

I have done this in COBOL when I learnt it You can't do it in C? Try it. Its easy. You can do it.
tuxfan is offline  
Old 26-07-2006, 12:28 AM   #5 (permalink)
Right Off the Assembly Line
 
aniishvara@gmail.com's Avatar
 
Join Date: May 2006
Posts: 30
Thumbs down Re: a small c problem

hey guys @ least tell me how to go abt that 18 ,19 etc nos...
ie how do i print the appropriate string saying eighteen ,or one or two,,,
for all the dates in a month!!!
aniishvara@gmail.com is offline  
Old 26-07-2006, 09:08 AM   #6 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: a small c problem

get each number and its place(ones place, tens place, hundreds place etc) and write a function to convert a number to text (basic like 9-nine) and add suffixes based on the place. remember there are lots of exceptions in this pogram because 18 is eight-een and 17 is seven-teen but 11 is not one-een. get what I'm saying? this confusion is only in 2 digit numbers till 20, so from that its easy
dheeraj_kumar is offline  
Old 26-07-2006, 09:17 AM   #7 (permalink)
Console Junkie
 
aditya.shevade's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 991
Default Re: a small c problem

Are you suggesting using the % (reminder tag?)

Aditya
aditya.shevade is offline  
Old 26-07-2006, 10:25 AM   #8 (permalink)
Right Off the Assembly Line
 
aniishvara@gmail.com's Avatar
 
Join Date: May 2006
Posts: 30
Unhappy Re: a small c problem

Quote:
Originally Posted by dheeraj_kumar
get each number and its place(ones place, tens place, hundreds place etc) and write a function to convert a number to text (basic like 9-nine) and add suffixes based on the place. remember there are lots of exceptions in this pogram because 18 is eight-een and 17 is seven-teen but 11 is not one-een. get what I'm saying? this confusion is only in 2 digit numbers till 20, so from that its easy
no ...u r not right!!! cos i have to print it as eleven for 11 , and not split the numbers as one one or for that matter 18 as eight-een
any numbershould be printed as we read it

like eighteen, 25 as twenty five itself and not like two-five as stated by u!!!

c this is the problem..and i do not want to use some stupid switch case or some else if ladders to print it appropriately!!!
aniishvara@gmail.com is offline  
Old 26-07-2006, 10:37 AM   #9 (permalink)
Alpha Geek
 
Join Date: Jan 2005
Location: earth
Posts: 804
Default Re: a small c problem

Quote:
Originally Posted by tuxfan
I am glad you guys didn't give out the code This surely is a homework problem! Solve it on your own man! These guys have given you enough hints!

I have done this in COBOL when I learnt it You can't do it in C? Try it. Its easy. You can do it.
hi tuxfan, so u know to code programs in cobol , cud u pls suggest me some ebooks, or tutorials on cobol cause i'm also learnin COBOL, for AS 400 and mainframes.
__________________
signature??? :???: Let Me Think About It!!!:-D
paul_007 is offline  
Old 26-07-2006, 11:40 AM   #10 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: a small c problem

Extract the last two digits: for one to twenty they have to have separate switches, for above twenty, you put one switch for each of the two digits. Then, go to the next digit for hundred, and so on...

Arun
sakumar79 is offline  
Old 26-07-2006, 02:37 PM   #11 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: a small c problem

Quote:
Originally Posted by paul_007
hi tuxfan, so u know to code programs in cobol , cud u pls suggest me some ebooks, or tutorials on cobol cause i'm also learnin COBOL, for AS 400 and mainframes.
That was many years ago! I don't remember anything in COBOL now. Completely out of touch
tuxfan is offline  
Old 28-07-2006, 10:19 PM   #12 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: a small c problem

@paul
http://www.csis.ul.ie/COBOL/
http://www.freeprogrammingresources.com/coboltutr.html
http://www.programmingtutorials.com/cobol.aspx
ilugd is offline  
Old 28-07-2006, 10:54 PM   #13 (permalink)
In The Zone
 
puja399's Avatar
 
Join Date: Jul 2005
Posts: 324
Default Re: a small c problem

Quote:
Originally Posted by aniishvara@gmail.com
no ...u r not right!!! cos i have to print it as eleven for 11 , and not split the numbers as one one or for that matter 18 as eight-een
any numbershould be printed as we read it

like eighteen, 25 as twenty five itself and not like two-five as stated by u!!!

c this is the problem..and i do not want to use some stupid switch case or some else if ladders to print it appropriately!!!
Create a dictionary in an array, and u don't have to use 'case' or 'else if ' ladders.
puja399 is offline  
Old 29-07-2006, 11:13 AM   #14 (permalink)
Right Off the Assembly Line
 
aniishvara@gmail.com's Avatar
 
Join Date: May 2006
Posts: 30
Question Re: a small c problem

Quote:
Originally Posted by puja399
Create a dictionary in an array, and u don't have to use 'case' or 'else if ' ladders.
wat is a dictionary in an array???
and how wud u create a dicitonary in an array???
aniishvara@gmail.com is offline  
Old 29-07-2006, 01:07 PM   #15 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: a small c problem

Methinks puja399 is confused, dictionaries are native python...or so I believe.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 29-07-2006, 05:22 PM   #16 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: a small c problem

c or c++?? @puja??
ilugd is offline  
Old 29-07-2006, 10:07 PM   #17 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: a small c problem

I think puja means that you use dictionary classes/templates to work with... Something such as http://www.codeguru.com/cpp/cpp/cpp_...icle.php/c869/ indicates... Creating maps will reduce the work in if-then-else clauses...

Arun
sakumar79 is offline  
Old 29-07-2006, 10:57 PM   #18 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: a small c problem

I think he should first check the number of Digits in given input.

ex. 10,286. Here it is 5. Hence the output string must contain "Thousand".

Then it is easy to write the code. Bcoz TEN is same for Lacks, Hundreds & TEN also.

Isn't it?
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 29-07-2006, 11:14 PM   #19 (permalink)
In The Zone
 
puja399's Avatar
 
Join Date: Jul 2005
Posts: 324
Default Re: a small c problem

Quote:
Originally Posted by sakumar79
I think puja means that you use dictionary classes/templates to work with... Something such as http://www.codeguru.com/cpp/cpp/cpp_...icle.php/c869/ indicates... Creating maps will reduce the work in if-then-else clauses...

Arun
Exactly so, however, u can implement a simple map in C using a 2D array.
puja399 is offline  
Old 30-07-2006, 03:56 AM   #20 (permalink)
In The Zone
 
Official Techie's Avatar
 
Join Date: Jan 2005
Location: Somewhere in motherboard
Posts: 439
Default Re: a small c problem

Why don't you start a new thread for your problem? Don't hijack threads
-tuxfan



i have a problem in c++


#include<iostream.h>
class outer { int a;
class inner {
int b;
public:
int c:
void prn(void)
{
cout<<endl<<"inner :: prn()"<<endl;
cout<<b<<c<<endl;
}
inner()
{
b = 5;
c = 10;
}

};
inner ob1;
public:
inner ob2;
void second(void)
{
cout<<endl<<"Outer::second()"<<endl;
cout<<ob2.c<<endl;
cout<<"A = "<<a<<endl;
ob1.prn();
}
outer()
{
a = 25;
}
};

void main()
{
outer ab;
ab.second();
ab.ob2.prn();
}





the errors are

--------------------Configuration: example of nested class - Win32 Debug--------------------
Compiling...
example of nested class.cpp
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(7) : error C2062: type 'void' unexpected
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp( 8 ) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(39) : error C2039: 'prn' : is not a member of 'inner'
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(3) : see declaration of 'inner'
Error executing cl.exe.

example of nested class.obj - 3 error(s), 0 warning(s)
__________________
Game Khelwanu Magazine Padhwanu Majjani Life

http://sudiptatech.blogspot.com/
http://sudiptamondal.blogspot.com/

Last edited by tuxfan; 30-07-2006 at 10:56 AM.
Official Techie is offline  
Old 30-07-2006, 06:52 AM   #21 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: a small c problem

I think in line 6, the end of the statement you have given : instead of ;. Change it and check.

Arun
sakumar79 is offline  
Old 30-07-2006, 07:30 AM   #22 (permalink)
In The Zone
 
Official Techie's Avatar
 
Join Date: Jan 2005
Location: Somewhere in motherboard
Posts: 439
Default Re: a small c problem

thanks a lot but this was a very silly mistake
__________________
Game Khelwanu Magazine Padhwanu Majjani Life

http://sudiptatech.blogspot.com/
http://sudiptamondal.blogspot.com/
Official Techie is offline  
Old 30-07-2006, 11:09 AM   #23 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: a small c problem

Quote:
Originally Posted by shirish_nagar
I think he should first check the number of Digits in given input.

ex. 10,286. Here it is 5. Hence the output string must contain "Thousand".

Then it is easy to write the code. Bcoz TEN is same for Lacks, Hundreds & TEN also.

Isn't it?
I think he will be better off converting the string to numbers first! So that if someone plays a mischief by entering say a string like "A5463" then the program doesn't process it at all.

Secondly, here're 2 hints!

Use the mod operator %
Use arrays with the strings "twenty" "thirty", etc.
Use some more arrays and variable of course. I guess these hints are enough
tuxfan is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Tenida
- by Charan
- by abhidev
- by Sujeet
- by Sarath

Advertisement




All times are GMT +5.5. The time now is 09:28 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2