![]() |
|
#1
|
|||
|
|||
Shapes Functions Version 2 - Arrays!If you don't know the last little challenge issued, here is the first thread:
http://www.gidforums.com/t-10450.html Basically, the new version of this will include naming shapes and assigning values to them. I'll copy and paste the general information about the next 'version' to this: Problem: Array of Shapes This nested-menu driven program will repeatedly do the following until user requests quit: get the user’s choice and call the appropriate menu. Then in this inner menu, get the user’s choice for the subtask and call the appropriate functions to produce and output the requested results. The differences from the last one are: 1. Cube option is removed for the purposes of simplicity 2. When entered a shape menu (Cylinder or Sphere), we are allowed to create shapes and name them. The names of the shapes will be single case sensitive characters from the English alphabet (26*2 = 52 different shapes can be defined in each menu). Main Menu will be the following: 1 Cylinder Menu 2 Sphere Menu 3 quit Cylinder Menu will be the following: 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu Sphere Menu will be the following: 1 Define a Sphere with radius 2 Define a Sphere with volume 3 Volume 4 List all Spheres 5 List Available Sphere Names 6 Swap uppercase and lowercase Names 7 back to Main Menu Sample Run 1 Cylinder Menu 2 Sphere Menu 3 quit 1 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 2 You have not defined ANY cylinders yet. Try again. 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 1 What is the name of the cylinder: a What is the radius and the height: 1 2 Done! 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 1 What is the name of the cylinder: a Overwrite the existing cylinder a [radius: 1, height: 2]? y What is the radius and the height: 3 4 Done! 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 4 What is the name of the cylinder: a The cylinder’s volume is 112. 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 4 What is the name of the cylinder: A Cylinder A is undefined. Try again. 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 6 ABCDEFGHIJKLMNOPQRSTUVWXYZbcdefghijklmnopqrstuvwxy z ***(Does not matter in which order these letters are written as long as you print all of the undefined ones) 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 1 What is the name of the cylinder: A What is the radius and the height: 3 8 Done! 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 5 A [radius: 3, height: 8] a [radius: 3, height: 4] ***(Does not matter in which order these letters are written as long as you print all of the defined ones) 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 7 Done! 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 6 BCDEFGHIJKLMNOPQRSTUVWXYZbcdefghijklmnopqrstuvwxyz 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 5 A [radius: 3, height: 4] a [radius: 3, height: 8] 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 8 1 Cylinder Menu 2 Sphere Menu 3 quit 1 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 2 You have not defined ANY cylinders yet. Try again. 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 List all Cylinders 6 List Available Cylinder Names 7 Swap uppercase and lowercase Names 8 back to Main Menu 8 1 Cylinder Menu 2 Sphere Menu 3 quit 3 Thank you! That is the basics. The problem that I am encountering is in the field of arrays. I'm first looking at the cylinder menu before advancing on to the sphere menu (which is why the sphere code probally won't have any use for now, that is still unmodified from the last project) Now, so far the program compiles correctly, but when I go to link it I need to first define two functions. swap and init. Here is the code so far: CPP / C++ / C Code:
The functions listed are at the beginning of the code. Another problem I have run into is defining the cylinder/sphere using arrays, and being able to call them to compute the volume/etc. I've put very little work so far into the actual shape menu functions that define volume because I'm a little lost on where to start. Last but not least, you've no idea how much help I have gotten from these forums. If not for you all, I would have a much harder time in my course this summer. So I'd like to thank you all in advance! Oh, and I made the code less horizontal heavy for you Walt EDIT: I got the Init value fixed. Now I just need to work on swap. EDIT2: Got init and swap defined now! Right now I'm having trouble when I define the cylinder |
|||
|
#2
|
|||
|
|||
Re: Shapes Functions Version 2 - Arrays!Alright, I got a lot of work done on it. The only thing I have trouble with is the 'swap' function now for the cylinder menu (remember, I haven't worked on the sphere menu yet.)
CPP / C++ / C Code:
Here is the swap function: CPP / C++ / C Code:
It doesn't seem to work 100%, and I'm having difficulty finding how to have this function work for this. Here is an example of what I did: defined cylinder A with rad 1, height 1 swap checked available cylinders, and ALL lowercases except j (?) were taken. weird.. |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic vs Static Arrays | WaltP | Miscellaneous Programming Forum | 5 | 16-Feb-2006 16:54 |
| Noob question on c arrays and functions | brett | C Programming Language | 1 | 20-Apr-2005 04:59 |
| versions | onauc | C++ Forum | 13 | 21-Nov-2004 00:24 |
| conflict between printf and stdarg.h va functions | mirizar | C Programming Language | 3 | 12-Jul-2004 09:11 |
| Help on passing in arrays in functions? | nusstu | C Programming Language | 10 | 02-Apr-2004 11:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The