C++ is a very useful desktop programming language and we like the Xcode IDE on a MacBook Pro to look after C++ projects.
These days a simple desktop C++ program project is found under “Command Line Tools”, and that sort of makes sense because you end up with something that can be run via the MacBook Pro’s Terminal application in Linux.
Today we set up two classes …
- WebApplicationRecord class handling 3 char[201] data members …
- webApplicationURL
- tutorialWebApplicationURL
- title
- WebApplication class with 2 int and WebApplicationRecord (respectively) data members …
- webappsSoFar
- **webapps
… the latter of which am sure you’ve guessed supervises the former, and as you’ve probably guessed the number of WebApplicationRecord (class) objects gathered during an execution is stored in webappsSoFar and the contents of those WebApplicationRecord (class) objects is contained in that **webapps pointer to a pointer (to a WebApplicationRecord (class) object), and as a lot of the readers will know or guess, the use of pointer to a pointer is a “red rag to a bull” sign that the memory required to organize all this is dynamically allocated. We actually ask the user how many WebApplicationRecord (class) objects the program can expect, and from that, use the WebApplication class method …
void setAside(int howMany) {
if (howMany == 0) {
webapps = new WebApplicationRecord*[100000];
} else {
webapps = new WebApplicationRecord*[howMany];
}
}
… to allocate the memory required.
We ask the user interactively for the WebApplicationRecord class data member information and want to thank this useful link for their char* safe_gets( char* result, int maxchars ) alternative to the old C function gets which is an improvement on std::cin (or its variations) in catering for a carriage return delimited string be stored in a char * variable.
And just so this “template” of an idea (hopefully for your expansion) has a little to “hang its hat on” we use some WebApplication “find” methods that return URL information, given a “title” input.
And so if you are a regular it is a bit of “channelling” of ideas from the recent PHP Themed Supervision Sixth Genericization Tutorial series of blog postings.
If you are into some C++ code you could try main.cpp and WebApplication.h as starting points.
If this was interesting you may be interested in this too.
5 Responses to Xcode C++ Web Applications Primer Tutorial