Tạo bởi Trần Văn Điêp|
Lập Trình C

Quản lý motobike - Quản lý xe cộ - Lập trình C

1. Data

Declare a structure:

struct motorbike_st {
char name[20];
char manufacturer[10];
char madein[12];
long int price;
};

In the main() function, declare an array of 3 motorbikes named motorbikeList.


2. Menu-Based Program

Create a menu-driven program with the following options:

  1. Input motorbike data

  2. Sort, display detailed information, and show statistics of all motorbikes

  3. Find motorbikes by manufacturer

  4. Save to text file motorbike.txt

  5. Exit


3. Input Motorbike Data

When the user chooses option 1, perform the following:

Example:

Enter data of motorbike 1:
Name: Air Blade
Manufacturer: Honda
Made In: Viet Nam
Price: 40000000

This module must be implemented in a separate function that:

  • Has a motorbike_st struct array as an argument.

  • Stores the input data into the motorbikeList array in the main() function.


4. Sort, Display Information, and Statistics

When the user chooses option 2:

  • Sort motorbikes in descending order by manufacturer.

  • Display detailed information of each motorbike in the following format:

No || Name || Manufacturer || Made In || Price ||
001 || Sirius || Yamaha || Viet Nam || 28000000 ||
002 || Air Blade || Honda || Viet Nam || 40000000 ||
003 || Dyland || Honda || Thai Lan || 150000000 ||

Display the number of motorbikes by manufacturer, for example:

Yamaha has 1 motorbike
Honda has 2 motorbikes

This module must be implemented in a separate function that:

  • Has a motorbike_st struct array as an argument.


5. Find Motorbike by Manufacturer

When the user chooses option 3:

  • Display: Enter manufacturer for search:

  • Find and display detailed information of motorbikes with the entered manufacturer (using the same format as in section 4).

  • If no motorbike is found, display:
    There are no motorbikes of this manufacturer.

This module must be implemented in a separate function that:

  • Has a motorbike_st struct array as an argument.


6. Save to Text File

When the user chooses option 4:

  • Save the name and manufacturer of each motorbike to a text file named motorbike.txt.

This module must be implemented in a separate function that:

  • Has a motorbike_st struct pointer as an argument.

  • Creates the file motorbike.txt in text mode.

  • Writes the name and manufacturer of each motorbike to the file.

  • Closes the file.


7. Exit

When the user chooses option 5, the program terminates.

Phản hồi từ học viên

5

Tổng 0 đánh giá

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó