Thursday, 21 October 2021

Chapter 21 // Exercise 14 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 14

Write a program (using the output from the previous exercise) to answer questions such as: 
"How many occurrences of 'ship' are there in a file?"
"Which word occurs most frequently?"
"Which is the longest word in the file?"
"Which is the shortest?"
"List all words starting with 's'"
"List all four letter words."

Github: 

So I know now why he wanted us to replace all punctuation with whitespace. It makes checking for words starting with certain characters a nightmare....it also makes words longer/shorter than they appear.

I didn't make this one interactive as the next one does that.

Wednesday, 20 October 2021

Chapter 21 // Exercise 13 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 13

Write a program to "clean up" a text file for use in a word query program; that is, replace punctuation with whitespace, put words into lower case, replace "don't" with "do not" (etc.), and remove plurals (e.g., ships becomes ship. Don't be too ambitious . For example, it is hard to determine plurals in general, so just remove an 's' if you find both ship and ships. use that program on a real-world text file with at least 5000 words (e.g., a research paper).


Another long one. I read question 15 though and was like "please...WHY".

I used this research paper:
Kacmarcik, G. and Kacmarcik, S. G. (2009) ‘Introducing computer programming via gameboy advance homebrew’, in Proceedings of the 40th ACM technical symposium on Computer science education - SIGCSE ’09. New York, New York, USA: ACM Press, p. 281. doi: 10.1145/1508865.1508969. 

It was one of the main papers that helped formed my research question for my Bachelors dissertation. It's only 4320 words....but I think Bjarne will let me off.

This exercise ended up disgustingly hacky and it prints out each word on a new line as he didn't specify any output specifications...just to "clean" it up.

Tuesday, 19 October 2021

Chapter 21 // Exercise 12 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 12

Provide a GUI interface for querying a file of Orders; e.g., "Find all orders from Joe," "Find the total value of orders in file Hardware," and "List all orders in file Clothing." Hint: First design a non-GUI interface; then, build the GUI on top of that.

Github: 

So the non-gui version can be found here:

I started to implement searching name, address, date and purchases, however it started taking up too much time and he only says name so I cut it back.

Chapter 21 // Exercise 12 - Principles & Practice Using C++

For the GUI version, I designed a new window called QueryOrderWindow and delved into a new FLTK widget; Fl_Text_Display. This class allows you display multiple lines of text with scrolling capabilities and other things but I only wanted to scroll.

I went over to GUI.h and added a new child of Widget called MultilineScroll_Outbox which creates an FL_Text_Display and Fl_Text_Buffer. You can then simply add text to the buffer. After that it was simply a matter of adding some buttons and pushing text to various places.

FLTK text Display scroll Chapter 21 // Exercise 12 - Principles & Practice Using C++

Sunday, 10 October 2021

Chapter 21 // Exercise 11 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 11

Provide a GUI interface for entering Orders into files.


I hate that he made this exercise. I also hate the next exercise. I've not used FLTK in so long. I've changed pc's since I last used it and I'm glad I made myself a guide. Having been about 9 months since I last used the fltk solution I had of course forgotten how everything worked. I appreciate though that he makes you do exercises using fltk later on.

I got a bit pedantic with this one but eventually settled on a system that allows you to add purchases and then checkout when you're done. When you checkout it clears everything and allows a new customer to be added. When you quit the program; it prints out all the orders to a text file. Thanks to stringstreams, I didn't need to change any input/output in the actual order file apart from changing ifstream to istream in one place.

FLTK Input Form - Chapter 21 // Exercise 11 - Principles & Practice Using C++

Chapter 21 // Exercise 11 - Principles & Practice Using C++




Saturday, 9 October 2021

Chapter 21 // Exercise 10 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 10

Compute the total value of the orders in the two files from the previous exercise. The value of an individual Purchase is (of course) its unit_price*count.

Github:

.