Course Programming Fundamentals (C language) 1 LAB 3 – struct data types Main content 1 Get used to struct data type definitions 2 Get used to member accesses with struct data types 3 Start simple dat[.]
Trang 1Course: Programming Fundamentals (C language)
LAB 3 – struct data types Main content:
1 Get used to struct data type definitions
2 Get used to member accesses with struct data types
3 Start simple data processing
4 Check coding styles
Practice:
1 Get used to struct data type definitions
1.1 Define a struct data type to represent the courses that you have studied so far Each course has:
- a course identifier which is a string of 6 alphanumeric letters
- a course name which is a string of at most 100 alphanumeric letters
- credit
- a course type which is REQUISITE or SELECTIVE
1.2 Define a struct data type to represent the electronic products in a store Each product has:
- a product identifier which is a sequence of 8 digits uniquely identifying this product from others
- a name which is a string with no space and special characters such as ‘.’, ‘;’, ‘!’, ‘@’, ‘#’,
‘$’, ‘%’, ‘^’, ‘&’, ‘*’, ‘(‘, ‘)’, ‘,‘, ‘-’, ‘*‘, ‘+’
- a design model which is a string starting with one capital letter and the rest with digits
- a delivery year which is a valid year in [1990, 2017]
- a unit price in dollar which is a positive floating-point number
- a care type which is FRAGILE or NORMAL
1.3 Define a struct data type to represent the distributors of those products all over the world Each distributor has:
- a name which is a string of only alphabetic characters
- a region which is AMERICA, ASIA, or EUROPE
- an address which includes a city name and a country name
- a product identifier which is a sequence of 8 digits for the main product distributed by this distributor
- a year when the distributor registered for the main product
1.4 Define a struct data type to represent the employees of an organization Each employee has:
- an employee identifier which is a sequence of 6 digits
Trang 2- a department which includes a department name, a department location which is LEFT, RIGHT, or CENTER, and a department annual budget
- an employee education level which is HIGH, AVERAGE, or LOW
- salary
- a starting hiring date
1.5 Define a struct data type to represent the tourists registered with a tour agent Each tourist has:
- a tourist full name containing only alphabetic characters and white spaces
- a passport number containing only one capital alphabetic character and 7 digits
- nationality
- fee
- a starting date
- an ending date
- the first visiting location which includes a location name, an x coordinate, an y coordinate
- the last visiting location which includes a location name, an x coordinate, an y coordinate
- a tour type which is SPECIAL or NORMAL or SALE
2 Get used to member accesses with struct data types
2.1 Define the variables, the printf, and scanf statements appropriate for populating the data
about the courses as follows:
2.2 Define the variables, the printf, and scanf statements appropriate for populating the data
about the products as follows:
Product
identifier Product name
Design model Delivery year Unit price
Care type
Trang 32.3 Define the variables, the printf, and scanf statements appropriate for populating the data about the distributors as follows:
Distributor
identifier Year City name Country name
2.4 Define the variables, the printf, and scanf statements appropriate for populating the data about the employees as follows:
Employee identifier
Full name
level Salary Hiring date Name Location Annual budget
123456 John
234567 Peter
Brown S&M LEFT 150.23 AVERAGE 20.4 01/03/2000
345678 Alice
Depp S&M LEFT 150.23 AVERAGE 20.2 03/04/2005
345689 March
Carter L&P RIGHT 200.39 LOW 15.6 06/05/2007 2.5 Define the variables, the printf, and scanf statements appropriate for populating the data
about the tourists as follows:
Full
name Passport Nationality Fee Starting date
Ending date
First location Last location
Tour type
John
Smith B1203457 English 15.3 13/2/2017 18/2/2017 L1 2.4 5 L2 5.2 8.3 SPECIAL Peter
Brown A3910385 English 13.2 23/12/2016 03/1/2017 L1 2.4 5 L3 4.8 7.5 NORMAL Alice
Depp B2384021 English 13 23/12/2016 03/1/2017 L2 5.2 8.3 L4 6.2 8.9 NORMAL March
Carter A3830291 English 10.5 28/12/2016 04/1/2017 L3 4.8 7.5 L5 6.5 9.2 SALE
3 Start simple data processing
3.1 Write a C program to enter your grades corresponding to the courses listed in question 2.1
In addition, ranking is used to show grades in a 4-scale grading system: ‘A’ for grade in *8.5, 10+, ‘B’ for grade in *6.5, 8.5), ‘C’ for grade in *5.0, 6.5), and ‘D’ for grade in *0, 5) Calculate your weighted average grade Display your average grade with two precision places and a corresponding rank using the appropriate expressions: arithmetic expressions, relational expressions, conditional expressions, and so on
Trang 43.2 Write a C program to calculate how many percents of the FRAGILE products there are, how many products were delivered in 2010, and how many products with the lowest unit price there are using the appropriate expressions: arithmetic expressions, relational expressions, conditional expressions, and so on
3.3 Write a C program to calculate the percentage of distributors in each region, to find the oldest distributor and the youngest distributor, to calculate how many distributors there are
in Vietnam using the appropriate expressions: arithmetic expressions, relational expressions, conditional expressions, and so on
3.4 Write a C program to list all the employees whose education levels are AVERAGE, to calculate the average salary at each department, to find the department with the highest annual budget, and to count how many employees have worked for more than five years using the appropriate expressions: arithmetic expressions, relational expressions, conditional expressions, and so on
3.5 Write a C program to find the tourist who has the longest tour, the farthest tour, the tourist who has the cheapest tour, the tourist who has the most expensive tour, and the most crowded tour type using the appropriate expressions: arithmetic expressions, relational expressions, conditional expressions, and so on along with the information given in questions 1.5 and 2.5
4 Check coding styles
For each C program that you have written, check coding styles with the following points:
- How have you used blank lines?
- How have you used tabs for alignment?
- How have you used comments in your source code files?
- Above all, how about your naming conventions? What have you named in your source code files?