• 10-21-2006
BurleMD
I need help with some programming that I've got due soon. Im pretty much completely lost, I really dont even know where to start. I know it says don't expect people to do your work for you, and Im not, but it would definetly help if someone could tell me what I need to do for this assignment. Id really appreciate it. Here is a copy of what Im supposed to do. Thanks.

Before you start, create a text file called xxxxxxx5.txt containing (this will be graded):

1. A clear statement of the problem, in your own words:
2. Describe the input and output information (use variable names and data types).
3. Develop a set of input and output values to use to test your program for several scenarios. Specifically:
a) A normal execution of each operation
b) A case where the user chooses an invalid menu selection (“87”, for instance)
4. Develop PSEUDOCODE for this problem, as discussed in class and in the text.
5. Develop your solution (see below for a more in-depth description)

Using User Defined Functions

Modularity allows us to “divided and conquer” the solution for a large problem solution. Each step in the decomposing outline can correspond to a function.
Reusability is a result of modularity where one module can be used by more that one program or module.
Abstraction is provided by the use of modules. The modules can contain the details of the tasks, and we can reference modules with worrying about the details.
Interface is the way to communicate with a module. For a function, the prototype provides the needed information to use a module.

 Carefully creating your pseudocode BEFORE you start will make your coding easier.

 Graphical Estimation. The Population Reference Bureau’s world population projection can be modeled by

where P is the population in billions. t is the year with t = 0 is the year 1990.

 Write a program the uses the above equation and produces the output as shown in Figure 1.
To do this you will create and use several functions as indicated in Figures 1 and 2.

Figure 1

Figure 2

 To get you started with your functions the prototypes are provided below. Use the function and variable names given.
void printDashes();
Prints a row of dashes.

int getEndYear();
Prompts for, reads, and returns the end year for the chart range.
NOTE: The year read must be tested to prevent entering a year outside the range, 1990 to 2100.

Print the header lines. Uses printdashes.

double calPop( int t );
Calculates and returns the world population for year t.

void displayPop( int year, int t );
Displays the year, population, and bar chart. Uses calPop and displayStars.

void displayStars( int numStars );
Prints a row of stars.

void displayPercChange( int begYear, int endYear, int beg_t, int end_t );
Displays a statement presenting the change of population. Uses finePerChange and printdashes.

double findPercChange( int beg_t, int end_t );
Caluates and returns the percentage of population change. Uses calPop.

 Other specifications.

e = 2.71828. Create a constant for E using a preprocessor directive.
t = 0 represents 1990.

 You DO have to do error checking on this assignment. There a specified limit for the end year.
• 10-21-2006
BurleMD

Oh, and the calculation for population is "p=11.14/(1+1.101e^(-0.051t))" where t=years
• 10-21-2006
manutd
Create a population estimator based on the formula. Do some error checking... And no, I can NOT give you any code on how to do this, because, as you said, this is a homework assignment.
• 10-21-2006
BurleMD
Quote:

Originally Posted by manutd
Create a population estimator based on the formula. Do some error checking... And no, I can NOT give you any code on how to do this, because, as you said, this is a homework assignment.

Yeah I figured that out by reading the information I posted. I didnt ever ask for someone to do it for me, did I? No. I just asked for some help on what I should do. If someone could post the steps I need to take to do it, that's all I probably need. Not asking for someone to do it, get it right.
• 10-21-2006
whiteflags
Well, he was just being frank I think. If you had made an attempt in this time, then you can post some code and explain your problems, and then we help you.

Since your professor laid out steps for you to follow, I would start by completing everything in the bulleted list. Type out those prototypes in a C file, and then read your book... After you complete the bulleted list, follow the numbered one.

Did you develop pseudocode like the professor asked? Did you try converting that to C? That's just about the only thing we can help you with.
• 10-22-2006
Quote:

Originally Posted by BurleMD
I need help with some programming that I've got due soon. Im pretty much completely lost, I really dont even know where to start. I know it says don't expect people to do your work for you, and Im not, but it would definetly help if someone could tell me what I need to do for this assignment. Id really appreciate it. Here is a copy of what Im supposed to do. Thanks.

Before you start, create a text file called xxxxxxx5.txt containing (this will be graded):

1. A clear statement of the problem, in your own words:
2. Describe the input and output information (use variable names and data types).
3. Develop a set of input and output values to use to test your program for several scenarios. Specifically:
a) A normal execution of each operation
b) A case where the user chooses an invalid menu selection (“87”, for instance)
4. Develop PSEUDOCODE for this problem, as discussed in class and in the text.
5. Develop your solution (see below for a more in-depth description)

Using User Defined Functions

First off, I should tell you I'm a hobby programmer only; that I know how to code this program, but not your instructor's other requirements: those you'll have to look at and judge for yourself.

Let's start with #1 - why not? We're getting to know the problem your code will solve here. We have a given - the pop. in 1990, and we have another given - the coefficient of growth for the population. So given this data point and growth coefficient, your program will ask the user what year they want to see the growth estimate for, and display it as a percentage of our 1990 population level, and show '*' asterisks to display the answer more graphically.

What datatype would population be? What about the percentage of growth (seems like a different kind is needed maybe?)? What about the user's year input? What datatype would that need to be?

That should give you a good kickstart into your description, your input and output (except your execution code).

When you're ready with #1, then take a gander at the functions (she calls them modules, I'll call them functions) that are required. Great list, your pseudocode just needs to tie them together (in the calling functions), and complete the work that each function needs to do. Which isn't very much.

This quote is wrong:
"Abstraction is provided by the use of modules. The modules can contain the details of the tasks, and we can reference modules with worrying about the details."

The key idea here should be WITHOUT worrying about the details. Funny stuff!

Read up on the page you listed, and review what your instructor wants for pseudocode, and get back.

• 10-22-2006
BurleMD
Okay, this is my best shot at writing it. I have no clue how those modular functions or whatever work, so I pretty much just wrote some crap. Im turning it in now cause frankly, Im tired of trying to dick with it and get it to work. If someone could tell my how I should have incorporated those into the program, i think it would help for next time. Thanks.

/* Matt
COMP-1200
Fall '06
Assignment 5

---------------------------------------------------------------

---------------------------------------------------------------
*/

#include <stdio.h>
#define e 2.71828

int main()

{

/*Declare all variables */

void printDashes();
int getEndYear();
double calPop( int t );
void displayPop( int year, int t );
void displayStars( int numStars );
void displayPercChange( int begYear, int endYear,
int beg_t, int end_t );
double findPercChange( int beg_t, int end_t );
float p, pop;
int year;

/*Get year */

printf("Enter a year inbetween 1990 and 2100: \n");
scanf("%d", &year);

/*Keep year in valid range */

if (year < 1990) || (year > 2100)

printf("Invalid year, must be between 1990 and 2100 \n");

else

/*Make t = 0 */

t = t - 1990;

/*Calculate the population */

p = 11.14 / ( 1 + 1.101 * e^(-0.051*t)

pop = p * 100

/*Print the inforumation */

printf(The year is : %i \n",year);
printf(The population is : %5.2f \n",pop);

/*Exit */

return 0;
• 10-22-2006
You've somehow vastly underestimated the amount of work involved in programming, sir. Programming is something that requires a lot of preparatory understanding - and you just haven't put the work into it yet.

If you don't study up on the background info (like how function calls work), then naturally, you will have to do a TON of "dicking around", to get function calls to work, in a program that requires them.

Did you prepare your text file describing the problem as required by the assignment, and your pseudocode?

The program itself is really not a very difficult one, if you'd like to work on it some more.

I know how frustrating it can be when you get behind on these kinds of assignments, but staying cool, and giving it some extra work, always pays off (well, as long as it doesn't drive you to become an alcoholic, anyway) :)

If you'll be around this evening, and want to work on it, pm me, and I'm at your disposal for 3 hours. I'm not going to do your homework, but I'm sure I can help you get on toward a better understanding of it.

• 10-22-2006
Quote:

Originally Posted by BurleMD
Okay, this is my best shot at writing it. I have no clue how those modular functions or whatever work, so I pretty much just wrote some crap. Im turning it in now cause frankly, Im tired of trying to dick with it and get it to work. If someone could tell my how I should have incorporated those into the program, i think it would help for next time. Thanks.

/* Matt
COMP-1200
Fall '06
Assignment 5

---------------------------------------------------------------

---------------------------------------------------------------
*/

#include <stdio.h>
#define e 2.71828

int main()

{

/*Declare all variables */

void printDashes();
int getEndYear();
double calPop( int t );
void displayPop( int year, int t );
void displayStars( int numStars );
void displayPercChange( int begYear, int endYear,
int beg_t, int end_t );
double findPercChange( int beg_t, int end_t );
float p, pop;
int year;

/*Get year */

printf("Enter a year inbetween 1990 and 2100: \n");
scanf("%d", &year);

/*Keep year in valid range */

if (year < 1990) || (year > 2100)

printf("Invalid year, must be between 1990 and 2100 \n");

else

/*Make t = 0 */

t = t - 1990;

/*Calculate the population */

p = 11.14 / ( 1 + 1.101 * e^(-0.051*t)

pop = p * 100

/*Print the inforumation */

printf(The year is : %i \n",year);
printf(The population is : %5.2f \n",pop);

/*Exit */

return 0;

The modules or functions that are mentioned are just logical boxes that we can take parts of a big problem and chip off, and put them into these boxes. Once a box (module or function) is right, we can seal it up with tape, and say "OK, that's done, now the problem is smaller than it used to be".

In addition to making the whole problem easier to deal with, it also helps insulate any problems of logic or syntax. Say you have a function like "DisplayStars", and all it does is just show the right number of '*''s for the populations percentage change. Once we get this DisplayStars function working right - then we know if there's a problem with the stars being displayed - it will be because (most likely), that function is getting the wrong input. Because we KNOW it will indeed display the stars correctly with the right input.

So DisplayStars is one of the functions or modules we'd use in this program. If we can group these functions into groups that are doing similar requirements, and still keep them small enough to easily debug, it's a big help in writing good code.

Here on the board, please use code tags around any code you submit. It keeps the right spacing, which is a HUGE help for people to understand your code. Code tags are just square bracks around the word code, to start the code, and then square bracket around the word code again BUT THIS TIME WITH A SLASH IN FRONT OF THE WORD CODE, to end the code. It looks like this, when it's done right:

Code:

```/* example of code tag use */ for (i = 0; i < 10; i++)   printf("\n I is now: %d", i);```
It's really what you want to add to any code you post up on the forum.