C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 21st, 2002, 01:07 PM
Neildadon Neildadon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 12 Neildadon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
C programming help!!

Hi im a 18 year student from the UK I really need help with a project i have to work on for my college assignment. Im learning borland c i would say my level is basic i have to write a bus ticket program which im struggling with.

This is what i have to do.

The public transport company BromBus, have decided they would like to investigate the feasibility of upgrading their traditional ticket machines further and have decided to offer the tender for the contract of producing a program written in C.

The new system is based around a VDU display and keypad for data entry. The specification from BromBus is as follows.

The route is made up of twenty stops, each of which is allocated a unique stop number starting from 1, busses will follow the same journey in either direction.

When run, the program must display an opening screen featuring the company name and a prompt for the boarding stop number; when a number is entered the appropriate address should print to the screen.

The driver should then see a prompt for passengers waiting to board, if the answer is No:

A default summary screen showing that both the number of passengers boarded and fares taken was zero.

If passengers are waiting to board, then the screen should display:

A prompt for destination stop number; that will be

accompanied by the address following entry.

Prompts for number of adults, children and OAP's

Note that passengers are treated as groups.

When the details are completed for a group, a ticket display should appear for 15 seconds showing details of:

Boarding stop number and address.

Number of adults, children and OAP's in the group.

Default fare and total fare for each category.

Total fare taken for the group.

The total number of passengers in the group.

The process described above should be repeated until no more passenger groups are left.

Standard Passenger Fare Charges

Passenger
Standard Fare

Adult
35p

Child
27p

OAP
15p

I have to use at least 3 functions in the code. I am really having problems understanding functions. i have tried many examples and read many web sites but most web sites arent very clear when explaining. i am using an old version of c called C++ 3.0

Any ideas or solutions to tackling this program would be most appreciated.

Many thanks

Reply With Quote
  #2  
Old May 21st, 2002, 02:17 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
a function consists of three parts:
- input values
- output values (usually only one)
- some code to produce the output value.

in c this looks like this:
Code:
int sum(int a,b) {
  return a+b;
}

this would be a mathematical function.

a function can also group a task in one central location:
Code:
char ask_driver() {
  char tmp;
  printf("Are there guests?");
  do {
    scanf("%c",tmp);
  } while ( (tmp!='y') && (tmp!='n') )
  return tmp;
}

this function takes no input parameters "()" and returns one character (weŽll use "y" for yes and "n" for no.). it does not allow you to type anything else.

functions are handy if you need to re-use code. if you type code twice and you correct a mistake in the first, 99% youŽll forget about the second time this code appears. say your bus company rises prices.
and your code will look more readable.
compare this:
Code:
int main() {
while (true) {
  printf("how many passengers");
  do {
    scanf("%d",&passengers);
  } while (passengers<=1)
  printf("how many adults");
  do {
    scanf("%d",&adults);
  } while (adults<=0)
  printf("how many children");
  do {
    scanf("%d",&children);
  } while (adults<=0)  
}
}

compared to:
Code:
void ask(char *question, *fmt;void *answer; int min) {
  do {
    printf(question);
    scanf(*fmt, answer);
  } while (*(int*)answer<=min);
}

int main() {
while (true) {
  ask("How many passengers","%d",&passengers,1)
  ask("How many adults","%d",&adults,0)
  ask("How many children","%d",&children,0)
}
}


isnŽt the second one much easier to understand?

disclaimer: no responsibility. this code is untested and probably needs modification before it compiles. sorry for the long post
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old May 21st, 2002, 02:50 PM
Neildadon Neildadon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 12 Neildadon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks

thanks for replying i have found your examples helpful.


When i start coding im unsure as to how i should start of this program.

How will i get the numbers 1- 20 to produce a street name when a stop number is entered ?

how will i get the program it pause for 15 secsonds ?

Reply With Quote
  #4  
Old May 21st, 2002, 02:55 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
for the numbers, this is called a list or an array.

in c they work like this:

Code:
char *station[20];

int init() {
  station[0]="Sesame Street";
  station[1]="Elm Street";
  station[2]="Downing Street";
  ... and so on
}

int main() {
  int nr;
  printf("Which station number?");
  scanf("%d",nr);
  printf("Station %d is called: %s.\n",nr,station[nr-1]);
}

the -1 is because c arrays always start with 0. so station[0] to station[19] will be used.
this would be a good use for a function (input nr, output station name)

pausing is afaik done using sleep(milliseconds), but could depend on your os (not sure).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > C programming help!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap