Chapter 9 homework, sum of cubes

Discussion in 'Mac Programming' started by larswik, Mar 26, 2011.

  1. larswik macrumors 68000

    Sep 8, 2006
    I have included a photo of my Chapter 9 Assignment. It is not due till next Monday since it is Spring Break but I want to do it before I forget.

    1. The goal is to use Functions to solve the problems
    2. I have to write my own Top Down Design
    3. I have to sum a cube?

    He wrote this on the board when he explained it.
    sqrsum := a*a + b*b + c*c + d*d

    The example on the paper use 10 10 10 20 and that returned 11000. But when I so 10*10 + 10*10 + 10*10 + 20*20 I come to a total of 700. I am not understanding this conversion?
    the code he used on the board
    function sqrsum (A,B,C,D : integer) : integer
        sqrsum := a*a + b*b + c*c + d*d
    How do you find the sum of a cube?



    Attached Files:

  2. dukebound85, Mar 26, 2011
    Last edited: Mar 26, 2011

    dukebound85 macrumors P6


    Jul 17, 2005
    5045 feet above sea level
    Your function example is a sum of squares, hence the a*a +b*b etc

    Sum of cubes is a*a*a +b*b*b etc and that will give your 11k as per what he got

    For your assignment, my approach would be to have 3 variables set to sum of squares, sum of cubes, and mean of squares and print out the desired variable to give your answer if the integers are within the desired range
  3. SidBala macrumors 6502a

    Jun 27, 2010
    Aah yes. First year computer courses. I wish I was back there.

    This year, my next assignment is to write what will pretty much be a complete game engine in less than a week. :(

    Anyway, you just need to follow the directions on the assignment page.

    Have 3 functions that return the appropriate values and setup the keyboard input with a switch case. Then call and print appropriate function/value.
  4. larswik thread starter macrumors 68000

    Sep 8, 2006
    Thanks for the help in understanding the Sum of a cube and the push in the right direction. I will start on it tomorrow night.

    This is the first assignment that I have to produce my own Top Down Design. The projects before this He would do them on the board and we would copy them down. I'll have to go over my notes on the last projects to get a better handle on it.

    Thanks Guys!

  5. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    I like the input validation part of this exercise. Valid input must be between 10 and 20 inclusive.

  6. larswik thread starter macrumors 68000

    Sep 8, 2006
    I am happy I got ubuntu Linux running under Parallels. It almost emulates the Lab version except for FPC not working correctly for compiling. But terminal works great using GPC. I should be starting on this tonight, with my Top Down Design.


Share This Page