SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 29: Arrays in structs

Name: _____________________________________________ Alpha: ___________________

Describe help received: ________________________________________________________

  • Due before class on Monday, April 3
  • This homework contains code to be submitted electronically. Put your code in a folder called hw29 and submit using the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Section 4 (Structs with pointers and arrays)) from the Unit 8 notes.
  2. Write a program called raffle.c that simulates a raffle lottery. Your program will first read in a series of names and exactly 4 raffle ticket numbers for each name, and then "draw" the winning number (by reading again), and finally print out the name(s) of all winners who have that winning number.

    Of course, you should create a struct for each person that contains their name as well as an array of their ticket numbers.

    Example runs:

    roche@ubuntu$ ./raffle
    How many people? 3
    Person 1 name: Dave
    Person 1 tickets: 650 205 592 377
    Person 2 name: Erin
    Person 2 tickets: 324 980 769 230
    Person 3 name: Jim
    Person 3 tickets: 442 230 296 230
    Winning ticket: 592
    Dave won!
    roche@ubuntu$ ./raffle
    How many people? 2
    Person 1 name: Erin
    Person 1 tickets: 324 980 769 230
    Person 2 name: Jim
    Person 2 tickets: 442 230 296 230
    Winning ticket: 592
    roche@ubuntu$ ./raffle
    How many people? 2
    Person 1 name: Erin
    Person 1 tickets: 324 980 769 230
    Person 2 name: Jim
    Person 2 tickets: 442 230 296 230
    Winning ticket: 230
    Erin won!
    Jim won!