Cars
by Omar Hamid-Chohan: L6 Age ~16
Introduction
Omar has based his program on his interest in cars. He guides the user first to select a make of car, then the model, then offers a choice of a trader page to buy the model or the manufacturer's page to see its details. Note the use of nested case statements for well-structured data input.
Omar includes 30 links to web pages of car models. In order to display each of these pages, he calls the ShellExecute function with the url of the required page as a parameter. (You can use this function in your coursework to access HTML help files).
If you decide to develop a similar program related to your own interests, we recommend that you consider from the outset how you could use procedures. You can save yourself a lot of copying and make the program easier to maintain.
The Program
program Cars; {$APPTYPE CONSOLE} { Copyright (c) 2011 Omar Hamid-Chohan Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License, as described at http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/ } uses SysUtils, ShellAPI, Windows; var Choice : integer; response : string; handle : HWND; const VehicleName1 = 'BMW'; VehicleName2 = 'Mercedes'; VehicleName3 = 'Audi'; begin repeat writeln( #13#10'Please type the number of your choice.'); writeln(' 1 ', VehicleName1); writeln(' 2 ', VehicleName2); writeln(' 3 ', VehicleName3); writeln(' 4 quit the program'); readln(Choice); case Choice of 1 : begin Writeln('You have selected ', VehicleName1); Writeln(' These are the models available:'); Writeln('1 series'); Writeln('3 series'); Writeln('5 series'); Writeln('7 series'); Writeln('If you would like to buy or know more about one of these vehicles'); writeln('type the number of the vehicle you are interested in.'); readln(choice); case choice of 1 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/bmw/1_series/postcode/wd187jf/radius/1500/quicksearch/true'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.bmw.com/com/en/newvehicles/1series/overview.html'), nil,nil, sw_show); readln; end; end; 3 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/bmw/3_series/postcode/wd187jf/radius/1500/quicksearch/true'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.bmw.com/com/en/newvehicles/3series/overview.html'), nil,nil, sw_show); readln; end; end; 5 : begin writeln('Yould you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('you will now be directed to an autotrader page on this car'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/bmw/5_series/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.bmw.com/com/en/newvehicles/5series/overview.html'), nil,nil, sw_show); end; end; 7 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/bmw/7_series/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car'); Shellexecute(handle, 'open', pchar('http://www.bmw.com/com/en/newvehicles/7series/overview.html'), nil,nil, sw_show); end; end; end; end; 2 : begin Writeln('You have selected ', VehicleName2); Writeln(' These are the models available:'); Writeln('1.A class'); Writeln('2.B class'); Writeln('3.C class'); Writeln('4.E class'); Writeln('5.GL class'); Writeln('6.S class'); Writeln('If you would like to buy or know more about one of these vehicles'); writeln('type the number of the vehicle you are interested in.'); readln(choice); case choice of 1 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/a_class/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/a-class/w169.flash.html'), nil,nil, sw_show); readln; end; end; 2 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/b_class/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/b-class/b245.flash.html'), nil,nil, sw_show); readln; end; end; 3 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/c_class/postcode/wd187jf/radius/1500/maximum-age/up_to_3_years_old/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/c-class/204.html'), nil,nil, sw_show); readln; end; end; 4 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/e_class/postcode/wd187jf/radius/1500/sort/priceasc/maximum-age/up_to_5_years_old'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/e-class/211.html'), nil,nil, sw_show); readln; end; end; 5 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/gl_class/postcode/wd187jf/radius/1500/sort/priceasc/maximum-age/up_to_5_years_old'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/gl-class/x164.flash.html'), nil,nil, sw_show); end; end; 6 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/mercedes-benz/s_class/postcode/wd187jf/radius/1500/sort/priceasc/maximum-age/up_to_5_years_old'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car'); Shellexecute(handle, 'open', pchar('http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passengercars/home/new_cars/models/s-class/w221.flash.html'), nil,nil, sw_show); readln; end; end; end; end; 3 : begin Writeln('You have selected ', VehicleName3); Writeln(' These are the models available:'); Writeln('1.A3'); Writeln('2.A4'); Writeln('3.A5'); Writeln('4.A6'); Writeln('5.A8'); Writeln('If you would like to buy or know more about one of these vehicles'); writeln('type the number of the vehicle you are interested in.'); readln(choice); case choice of 1 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/audi/a3/postcode/wd187jf/radius/1500/quicksearch/true'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.audi.co.uk/new-cars/a3.html'), nil,nil, sw_show); readln; end; end; 2 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/audi/a4/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.audi.co.uk/new-cars/a4.html'), nil,nil, sw_show); readln; end; end; 3 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/audi/a5/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.audi.co.uk/new-cars/a5.html'), nil,nil, sw_show); readln; end; end; 4 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); readln; Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/audi/a6/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.audi.co.uk/new-cars/a6.html'), nil,nil, sw_show); readln; end; end; 5 : begin writeln('Would you like to buy or learn more about this vehicle?'); writeln('Type "buy" or "learn more"'); readln(response); if response = 'buy' then begin writeln('You will now be directed to an autotrader page on this car.'); Shellexecute(handle, 'open', pchar('http://www.autotrader.co.uk/search/used/cars/audi/a8/postcode/wd187jf/radius/1500/sort/priceasc'), nil,nil, sw_show); readln; end; if response = 'learn more' then begin writeln('You will now be directed to the official website for this car.'); Shellexecute(handle, 'open', pchar('http://www.audi.co.uk/new-cars/a8.html'), nil,nil, sw_show); readln; end; end; end; end; end;//case until Choice = 4 end.
Remarks
Could you write a similar program related to your own interests?