Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-04-2007, 11:41 AM   #1 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
need help with class assignment

the question they gave us was:

Your friend Joe saves pennies in a jar, which he empties every month when he goes tothe bank. You are to create a problem that allows him to enter the number of pennies, and then calculates and displays the number of dollars, quarters, dimes, nickels, and pennies he will receive when he trades in the pennies at the bank.

I need to code this and confused on how to can anyone help?
tiggerzone is offline   Reply With Quote
Old 02-04-2007, 11:52 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
First of, try and see how many dolars it fits into, say he has 881 pennies, that would be 8 dolars, then theres 81 pennies left. take the highest number of quaters it would be, which is 3, that'll leave you with 11 pennies, then take the highest number of dimes that'll provide, which is zero, this will leave 11 pennies, then take the highest number of nickels that'll provide, which is two, which will leave you with 1 pennie...
So the outcome to that will be:

Dollars: 8
Quarters: 3
Dimes: 0
Nickels: 2
Pennies: 1

Anyway, you will allways use the greed paradigm..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 02-04-2007 at 12:30 PM.
redhead is offline   Reply With Quote
Old 02-04-2007, 12:18 PM   #3 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
thanks for response but...

I need a write a programming code for that question and then desk check my answer.
tiggerzone is offline   Reply With Quote
Old 02-04-2007, 01:36 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
Here is one in ML
Code:
val values = [(100, "Dollars"), (25, "Quarters"), 
      (10, "Dimes"), (5, "Nickels"), (1, "Pennies")];

fun head([]) = []
    | head((x,y)::xs) = x :: head(xs);

fun tail([]) = []
    | tail((x,y)::xs) = y :: tail(xs);

fun combine([],[]) = []
    | combine(x, []) = []
    | combine([], y) = []
    | combine(x::xs, y::ys) = (x,y) :: combine(xs,ys);

fun count([], value, result) = result
    | count(x::xs, value, result) =
        if value = x then
                count(xs, value, result +1)
        else
                count(xs, value, result);

fun count_all([], []) = []
    | count_all([], y) = []
    | count_all(x, []) = []
    | count_all(x, y::ys) = count(x,y,0) :: count_all(x, ys);

fun change (coinvals, 0) = []
  | change ([], amount) = []
  | change (c::coinvals, amount) =
      if amount<c then change(coinvals, amount)
                  else c :: change(c::coinvals, amount-c);

fun make_change(value) = 
  combine(
      count_all(
         change(
            head(values), value
         ), head(values)
      ), tail(values)
  );
Quote:
I need a write a programming code for that question
I'm not here to do your homework, show us how far you've gotten, then we might help...

If you know functional programming, then my ML version will provide great help.. If not, you're not any further than you were to begin with..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-04-2007, 02:04 PM   #5 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
whats ML

I need it in C++ coding I'm just a beginner so any help would be appreciated
tiggerzone is offline   Reply With Quote
Old 02-04-2007, 02:11 PM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
Then I would say the structure would be something like:
  • if amount bigger than 100, then dollars equals amount/100 and change amount to amount%100
  • if amount bigger than 25, then quarters equals amount/25 and change amount to amount%25
  • and so forth...

//edit
ML is a functional programming language the Moscow ML version was developed by an old professor of mine. So I started out learning LISP and ML as the first two programming languages.

By the way, welcome here at Code Newbie
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 02-04-2007 at 03:12 PM.
redhead is offline   Reply With Quote
Old 02-04-2007, 04:18 PM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
% would work

881 % 100 leaves 81

or

881 / 100 = 8
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 02-04-2007, 10:18 PM   #8 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
how do you code this assignment in C++

thanks for the message but the question wants us to complete a IPO chart and use the chart to code the program. This is an introduction course to programming with c++ I have already completed the IPO chart I just need some asssistance with the coding of the program to complete this exercise.

Thanks
tiggerzone is offline   Reply With Quote
Old 02-04-2007, 10:55 PM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
Ok, you convinced me.. .I'll do the start part, you can then complete it...
Code:
#include <iostream>

int main()
{
  int amount=-1;
  while(amount < 0){
    std::cout << "Input amount of pennies: " ;
    std::cout.flush();
    std::cin >> amount;
    if(amount < 0)
        std::cout << "It's impossible to have negative amount" << std::endl;
  }
  if(amount >= 100){
    std::cout << "Dollars:\t" << amount/100 << std::endl;
    amount = amount %100;
  }
  if(amount >= 25){
    /* now you continue */
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-05-2007, 10:06 PM   #10 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
I figured out the coding on this one but I can't figure out the calculatons on this exercise can some one help I'm a beginer with this c++ coding stuff so help would be greatly appreciated.
tiggerzone is offline   Reply With Quote
Old 02-05-2007, 11:28 PM   #11 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
Alright, here is the missing code to this one:
Code:
    std::cout << "Quarters:\t" << amount/25 << std::endl;
    amount = amount %25;
  }
  if(amount >= 10){
    std::cout << "Dimes:\t\t" << amount/10 << std::endl;
    amount = amount %10;
  }
  if(amount >= 5){
    std::cout << "Nickels:\t" << amount/5 << std::endl;
    amount = amount %5;
  }
  if(amount >= 1)
    std::cout << "Pennies:\t" << amount << std::endl;
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-06-2007, 02:46 AM   #12 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
calculatons have nothing to do with c++, learn your mathematics
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 02-06-2007, 11:03 AM   #13 (permalink)
tiggerzone
Recruit
 
Join Date: Feb 2007
Posts: 18
tiggerzone is on a distinguished road
but how do you code the calculations
tiggerzone is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[C#] Casting from derived class to base class Melon00 MS Technologies ( ASP, VB, C#, .NET ) 0 06-06-2006 08:34 AM
Help with C++ & Win32 in a class DIY_Gamer Platform/API C++ 1 07-29-2005 07:45 AM
Class using a specific instance of another class? is this possible? abs Standard C, C++ 5 02-08-2005 03:12 PM
someone please help kickerman97 Java 3 10-19-2004 03:19 PM


All times are GMT -8. The time now is 08:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting