Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assignment 7 Solved - Introduction to C Programming - Spring 2012 | CSE 251, Exams of Computer Science

Material Type: Exam; Class: Programming in C; Subject: Computer Science & Engineering; University: Michigan State University; Term: Summer 2005;

Typology: Exams

2013/2014

Uploaded on 12/07/2014

derbende
derbende 🇺🇸

3 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Assignment 7 Solved - Introduction to C Programming - Spring 2012 | CSE 251 and more Exams Computer Science in PDF only on Docsity! Introduction to C Programming Assignment #7 Instructor: Hao-Hua Chu Spring Semester, 2012 Due 5/16/2012 Like assignment 6, you don’t have to send your homework to TA, instead we require you to have a quick demo for your program in the class on 5/16. However if you have any problems about the assignment, feel free to send an email to TA [TimeStringAlpha@gmail.com] with the title [C11]. In this assignment, we want you to get more familiar with a structure array and an array of structure pointers, and compare the pros and cons between each other. Question 1. Please design a program that help us sort out a series of positive numbers in decreasing order. We will enter no more than 20 numbers. Enter how many number will be entered> 7 Enter number 1> 15 Enter number 2> 62 Enter number 3> 8 Enter number 4> 59 Enter number 5> 32 Enter number 6> 66 Enter number 7> 27 The result is: 66 62 59 32 27 15 8 (system pause and program terminate) Question 2. Please design a student ranking program. A student has 4 subject grades, which are chinese, math, english and computer. We will enter each subject grade of each student into your program, and your program should be able to sort these students according to the total points they get in descending order. The skeleton code should be like the following: typedef struct { char name[100000]; int chinese, math, english, computer; int total; } student; void main() { student people[5]; ... ... } The structure student keeps the information of one student, which includes student name, 4 subject grades and total points the student get. You may have the question that why we need a 100000-character-size char array to record a student name, the reason is some students come from other planet and have a super long name ;-). Since many students’ information will be entered, we have to declare a student structure array in the beginning of main function to keep the information. Your program should have the following input & output. Enter how many students> 4 __Student 1’s name> Mary __ Chinese> 62 ____Math> 99 __ English> 63 _ Computer> 87 __Student 2’s name> Alice __Chinese> 98 ____Math> 87 __ English> 84 _ Computer> 99 __Student 3’s name> Bob __Chinese> 92 ____Math> 60 __ English> 58 _Computer> 62 __Student 4’s name> John __Chinese> 78 ____Math> 72 __English> 88 _Computer> 76 ================================= Rank Chin Math Eng Com Total Name 1 98 87 84 99 368 Alice 2 78 72 88 76 314 John 3 62 99 63 87 311 Mary 4 92 60 58 62 272 Bob (system pause and program terminate) Question 3. Now you want to improve and upgrade your program. In the question 2 your program can only enter information of up to 5 students, but in this question we require you modify your program which can handle up to 50 student records. Thus in the beginning of your code, you also have to declare the structure student same as question 2, but the skeleton of main function should be like the following instead: void main() { student *people[50]; // comment: then you have to malloc() 50 structures ... } The main difference is that we change the declaration of structure array into an array of structure pointers. Basically your program should have the same input & output as question 2, but we provide another larger test data for you to test your program.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved