Beruflich Dokumente
Kultur Dokumente
Objectives:
This set of experiments will: 1. Allow the student to demonstrate the C programming skills learned during the first part of ECE2551.
Problem Statement:
In this lab, you are tasked to create a program that either: 1. Expands on any of the labs covered so far. 2. Demonstrates the C programming skills covered during class in your own small project.
Program Requirement:
We will implement a program to covered all topic in class: 1. Selection statements. 2. Loops and Logic. 3. Pointers and Arrays. 4. String. 5. Dynamic Memory Allocation and Pointer Indexing.
Project Specification:
I think about doing a mini project for booking the tickets at the airport. The scope of project is: Start the program, you can see all the cities you can fly to. The menu is available for you to choose the option: 1. See the details of the flights ( see the details of ticket to the specific city about where we go, the number of tickets remain, the departure hour, the arrive hour and the price to fly). 2. Book tickets ( you can book the ticket if the ticket in pocket isnt empty and the price of all tickets you book is lower than your account balance) When booking successfully, you balance and the number of tickets in pocket will be decreased. Note: You can book tickets once you have changed your account number for at least one time. 3. You can change your account number, when change with any number you want, I assume I will provide you 500$ for this account(not in the real life). 4. You can see information about your bank account (account number and balance). Note: You can see info once you have changed your account number for at least one time. 5. Exit the program.
Selection Statement:
Slection statement is very popular in the programming language:
Some of them: an if statement with no else is a one-way selector an if-else statement is a two-way selector a switch or case statement is an n-way selector With the menu, I use an n-way selector:
switch (opt) { case 1: //see the details of the flight break; case 2: //Book tickets break; case 3: // change bank account number for booking break; case 4: // show information of your bank account break; case 5: //exit the program break; default: //print the error when don't find the suitable option printf("Error: Unknown option!"); break; }
(1)
With the logics, you can see I always use it in my program, logic is about determining one logic expresion if its true or false to excute some business code.
String:
From source (2) above, I have used string to represent the name of each city. The string here is an array of character. Use strcmp(string compare) to compare two string and decide if its equal or not. Learnt in this course many other function supported in string.h library: strcpy, strlen
while (strcmp(*(city_name+i),"X") != 0) {
Source Code:
Please reading file Lab7.c attached. Copying source code to word may destroy some viewing structures.
Conclusion:
After learning this course, I can understand all the materials with some topics: 1. 2. 3. 4. 5. Selection statements. Loops and Logic. Pointers and Arrays. String. Dynamic Memory Allocation and Pointer Indexing.
After that, I can use all knowledge I have studied from this to write my own project: Ticket booking at the airport which can resolve some simple problems.
Some Screenshots: