Friday, October 3, 2014

Day 7: Struct

1.  Write a C Program to store student data in a structure. The data should include student ID, name, course registered for, and year of joining. Write a function to display the details of students enrolled in a specified academic year. Write another function to locate and display the details of a student based on a specified student ID.




2. Write a C program to store 5 lengths in a structure array. The lengths should be in the form of yards, feet and inches. Sort and display the lengths.

3.      Write a C Program to store employee details in a structure array. The data should include emploee ID, name, salary, and date of joining. The date of joining should be stored in a structure. The program should perform the following operations based on a menu selection:
a.       Increase the salaries according to the following rules:
Salary Range
Percentage increase
<= 2000
15%
> 2000 and <= 5000
10%
>5000
No increase
b.      Display the details of employees who complete 10 years with the company.


4.   Write a C program to implement an inventory system. Store the item number, name, rate and quantity on hand in a structure. Accept the details for five items into a structure array and display the item name and its total price. At the end, display the grand total value of the inventory.

5.  Write a C program to store the names and scores of 5 students in a structure array. Sort the structure array in descending order of scores. Display the top 3 scores.

*Note:

Struct là 1 kiểu dữ liệu trong C nhưng không phải do thư viện của C định nghĩa, mà do chính người dùng định nghĩa.

Cú pháp của struct:
typedè struct Tênstruct{
     Kiểudữliệu1 Tênbiến1;
     Kiểudữliệu2 Tênbiến2;
}

Cách khai báo biến: TênStruct TênbiếnStruct;

Khi muốn truy nhập đến các trường của struct ta dùng cú pháp: TênbiếnStruct.TrườngStruct.

No comments:

Post a Comment