Well done to those that have completed the drill question (well, at least you did the “EASY” one) last week. To those that did my STUN question, KUDOS!!!! By doing this exercise, you have examine the buggy code and correctly identified the syntax errors, logic erros and some went further of discovering the differences of using “cin” and “getline”. The application and synthesis skills, such as isolating the buggy portion of the code, using the debugger, and reading error message from the IDE are particularly important especially in programming. These are the skills that I hope you can exhibit or demonstrate at the future assessments to come.
For those that have yet to attempt, please give it a try. And for those have done, try out the “HERO” question. Everybody loves to be a hero and get "worshiped" (I assumed that is).
Pointer is used for example when sorting a data structure. It is “expensive” to move the data physically, hence, changing the value of the pointer that points to the data is considered “cheaper”.
Below is a chunk of code that demonstrates pointers, the differences when pointers are applied to “char array” and “int array”. YOU are MOST WELCOMED to add more examples of using a pointer in c++.
For those that have yet to attempt, please give it a try. And for those have done, try out the “HERO” question. Everybody loves to be a hero and get "worshiped" (I assumed that is).
Pointer is used for example when sorting a data structure. It is “expensive” to move the data physically, hence, changing the value of the pointer that points to the data is considered “cheaper”.
Below is a chunk of code that demonstrates pointers, the differences when pointers are applied to “char array” and “int array”. YOU are MOST WELCOMED to add more examples of using a pointer in c++.
Pointers come a long history in C and C++, some hate it so much but some really love it. Take it like a durian. Pointers enable the manipulation of the memory directly. PLEASE be EXTRA meticulous when it comes to programming pointers. Commented code really helps a lot for others to look, learn, debug another programmer’s code.
Now Comes the drill question for pointer. Write a program that calculates the volume of a cube (A x A x A), which need to satisfy some "requirement" identified from the "problem analysis" (which is done by me for you)
1. Read in 2 inputs from the user
2. Code a function that takes in this 2 parameter passed by reference and the result is stored in another variable, which is also accessible by the pointer ptrArea. Print out the area for the user.
3. Code another function, which takes in the ptrArea and calculate the volume of the cube.
Now come to the drill question array. Arrays are “containers” that can be used to store data in a structural manner. There are some disadvantages when it comes to using array. First, memory need to be allocated first (static). What happends when there are many copies of the same programme are running? Since memory is allocated, and used up but there are more data to come, array do not have the flexibility to increase like the vector. What are the other cons of using array compare to any other data structure?
Consider using “arrays”. Code a simple 100 seat cinema booking system that will do the following
1. Given (x,y) coordinate set the seat to be occupied.
2. Suggest a scheme/algorithm that detects duplicate seat entry.
48 comments:
http://snipt.net/embed/07d477ae9dde683807a810ab2fabc913
Name: Wang Liang Class: 2B05
http://snipt.net/embed/8112279aa27930e77101083b09b8ce27
http://snipt.net/embed/40dca785e3ae696688bfbf97cb531af5
http://snipt.net/embed/e159fd1ca49c1afb07d8f85122f87810
http://snipt.net/embed/a86bbafeb7206f0726f607408fefd46e
http://snipt.net/sgxbuster/wk2-day-2?key=5eecf85df18c3eee67f67cf8b64c026a
http://snipt.net/edwinraja/sum-of-even-numbers?key=a86bbafeb7206f0726f607408fefd46e
http://snipt.net/J0k3r/sum-of-even-number-09?key=31018839872a96ea85dda0981e72c489
http://snipt.net/puteraafiq/array-1?key=ba60528fdea2ecd74e973e98ff95be7d
http://snipt.net/embed/e3e621347d131dcc07aa0a7248d218df
http://snipt.net/Soonbengisgougou/sum-of-even-numbers-using-for-loop
http://snipt.net/alvinthen/pointer-usage?key=cc394f1347eade9e648d60c01b081909
http://snipt.net/asdsieg/pointer-9?key=c4685b9cbbef0fcfe46e03066a25af4f
http://snipt.net/bigshow/1st-code/
http://snipt.net/jellybanana/pointer-testing/
http://snipt.net/sa198/by-qi-hao-dcpe2a03?key=45a284d3f31584ea9ea0c9da0d1b6c1e
http://snipt.net/UJuzGtJacked/done-by-felix/?key=a35bb84adfcebabe4c9785f9dc5b277a
I wrote the wrong class, my class is DCPE/2B/03
http://snipt.net/ganesh92/cube-volume-and-area/?key=ae7918331ae181ccb2c8296fe40a235b
Name : Ganesh Class : 2B03
http://snipt.net/hengnee/class-assignment-i-realised-my-firewall-that-i-downloaded-blocked-my-program-so-i-had-to-uninstall-it-anyways-it-works-now/
http://snipt.net/xiaofei/c-2/
http://snipt.net/Stish/area-and-volume?key=c07a202057d4ae4a0a870d44648bcbdf
http://snipt.net/yangershiwo
http://snipt.net/alvinthen/sum-of-even-number-using-array?key=428cadf68b255f327448b74f3143d73c
http://snipt.net/asdsieg/array-2?key=27306d549c408a8a8a866a269ebb292c
http://snipt.net/bigshow/week2
http://snipt.net/Stish/sum-of-even-nums?key=77a9e5fc20f8607fdb20dd7d4ce94b82
http://snipt.net/xiaofei/add-the-no-in-array/
http://snipt.net/yangershiwo
http://snipt.net/UJuzGtJacked/array-3?key=05bd295a11f64e9e65e12bc05aa40a52
http://snipt.net/tintundcpe2b03
http://snipt.net/tintundcpe2b03
cinema booking system
@felix, nice work done.
@ the rest of the guys that written code, keep the code coming in!~
http://snipt.net/UJuzGtJacked/improved-cinema-booking/?key=e6e8d35b8e46dc9a92bcabc3a9d44db1
Sorry sir. I think i accidentally copied the wrong link. This is then the right one.
http://snipt.net/asdsieg/cinema-1
http://snipt.net/Wizardgenesis/row-and-column-example/
http://snipt.net/hengnee/not-successful-version
sorry, but it seems like I cannot replace the zero with a one...
http://snipt.net/alvinthen/fail-version?key=330cb2ea513ecad86fc9f9ed7faebbd6
cannot manage to detect duplicate seat numbers
@felix, u also posted the wrong link on the post for common mistakes
@heng gnee, which line is the one that is giving the problem? you need to identify by stepping thru ur program.
@alvin, checking of the duplicate booking is as simple as comparing the content of the cell in the array.
eg
temp = arr[i][j]
if (temp == 1) //assume 1 is booked
cout<<"msg"
@all,,
some of you declarare 3 arrays instead of a 2D array....
using of a 2D array let us modify the req easier, eg cinema expanded to 100x100 seats instead of 10x10 seats.
if u use 3 arrays as 3 rows, u gotta declare 100 arrays ==> tired larrrr
Example of 2D array:
int ar1[2][2];
ar1[1][2] = 1;
cout << ar1[1][2];
http://snipt.net/xiaofei/cinema-booking-3
why after i book the place ,the output of seat change the whole column not that particular seat?
@Li Xiaofei
You declared your array as zero.
@Li Xiaofei
Ah sorry, I realized that my answer wasn't really clear. You declared the size of your array as [0][0].
@HY
thanks ya now it works
@xiao fei, good 1. keep the code coming in
zomg after so long i finally understand what you are talking about mr teo...now my cinema is 100% working
http://snipt.net/alvinthen/fail-version?key=330cb2ea513ecad86fc9f9ed7faebbd6
@Alvinthen
You could have just used a 2D array. If you had used a 2D array, the seat checking part would only be 2 lines long.
Post a Comment