Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 2: Hello World Description and purpose: This is a simple assignment to walk through the steps of modifying a simple Hello Worid program and

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Assignment 2: Hello World Description and purpose: This is a simple assignment to walk through the steps of modifying a simple "Hello Worid" program and submit it through Github. The purpose of this activity is to demonstrate proper use of header files, to use github, to explain proper coding processes, and to demonstrate command line parameters. Background - You will need a Gathub account for this. Start with the Github Classroom guide, read it all very carefully (if you have not already, but you should have) - You will need to install git (if you have not already, but you should have). - Install g++ if you need to. This will be very different depending on your operating system. Before you do anything though, see if you have g++ already installed by typing 9+++version at the command line (see below for an example). Windows Users: If you download and install an IDE Ike CLion or DewC++ it may install g++ for you (not sure about this, you will need to check your install). You can try MinGwy or Cygwin. This will require some research and trial-and-error on your part (and it's good for you). Mac Users: Since Mac is essentially a variant of Unix, g++may aiready be installed. Go to a command prompt and type g++-.version and see if it works (make sure it reports back g++and not clang). If you see a g++response, you're all set. If it does not, students have reported success with this tutorial, and this one, and this Stack Overfiow page (that post is old, so be careful). This may require some research and trial-and-error on your part (and its good for you). - Linux Users: You're probably good to go. To make sure, type g+t-version at a command prompt, and see if it works. If it doesn't, any simple Google search will quickly give you the answer for your version of Linux. - If you have gi+ set up correctly. you will be able to execute g++-version at any command prompt and see something like this... alexalex-Laptop:-5 g+t.-version g++ (Ubuntu 7.5,83 ubuntul 18,84 ) 7.5.0 Copyright (C) 2017 Free 5 oftware Foundation, Inc. This is free software; see the source for copying conditions. There is No warranty; not even for VERCHANTABILITY or FITNESS FOR A PARTICULAR PLRPOSE. - Even if you have g+t installed correctly. you will probably need to adjust your PATH environment variable to be able to call g++from any location. This is a good time for you to start researching like a programmer, so if you don't know what the PATH is, start searching and reading. - Note the following carefully1 If you install any IDE like Deyt+ or CLion or Ylsual Studic (all of which are free to students) you will be able to create, compile, and run programs from the IDE itself and not need the command prompt. However, running in an IDE is not the same as compiling from the command line. You may be able to get away with this and you may never have to compile at the command line in this class, and if you're lucky, no one wil ever know the difference (don't bet on it though). However, there is a danger in this. Compiling from an IDE can mask errors and can allow you to use non-standard C++ Ibraries (especially if you use Visual Studio or if you are on a Mac). Then when you turn in your code it will not compile with g++ under Linux and you will get 0 . The only true test of your code is compiling and running at the oommand line using g++, Also, if you're going to be a professional programmer, you cannot avoid leaming the command line and how to set up a proper development environment. May as well get to it now. nstructions / Specifications: - Follow the Assignment Specific Instructions using this GitHub assignment invite hitps:/lclassroom github comia/b9rFNLD- - Once you have completed the Assignment. Specific Instructions up to "Now you are ready to begin working" step, you will have four files on your computer, README.md, -gitignore, main.cpp, main.I - Note that you did not need to make a .gitignore this time, it's made for you, but you should study it s you understand how gitignore works. - Edit your local README.md so it says, "my first C++ program in data structures class" instead of wh it currently says. - Make two blank (empty) files locally in your project folder: functions.cpp and functions.h. - In both new files put your comment header. - In functions.h put in the \#ifndef directive below your comment header like so... Note that all the code you will later place in this file will go inside the \#ifndef directive after the first \#define as shown and before the \#endif. - In main.h, add \#include "functions.h" right below \#include - Save all your files and compile them at the command line with the following command g++I.cpp (on Windows you may need to use g++ - // main.cpp functions.cpp). This will create an executable called a.out (Mac and Linux) or a.exe (Windows). If it does not compile, read the error, and fix your program until it compiles. - Run your program at the command line. Type a.out (Mac and Linux) or a (Windows) and it should ru If it doesn't, try /a.out (Mac and Linux) or .la (Windows). - If everything worked correctly, your command prompt actions should look similar to this. - Assuming it all worked it's time to commit and push. If it didn't work, fix it. Add: git add README.md functions.cpp functions.h main.h Commit git commit -m "initial commit" Push: git push -u origin main - Go to your repo on Github and see that all your files are there and up to date. If they aren't, fix it. Now you are ready to code... - In main.cpp change "Hello World to "My Command line analyzer.." Add this line below the cout line you already have cout "The number of command line parameters are: " argc endl; - Compile and run your program three ways: a.out or a on Windows a.out hello or a hello on Windows a.out hello world or a hello world on Windows Obsorve the outputt arge is a count of the things on the command line. - Stop again and add and commit with an inteligent message about what you just did. You can push also, but it's not necessary. This is a proper development process. Make a small self-contained and logical change, stop and test it, and if it works, commit with an intelligent commit message. If you go much further than this without testing, you're doing it wrongl - Now stub a function called string_length in your functions module (a 'stub' is a prototype plus an empty function definition). In functions.h add a prototype inside the \#ifndef directive int string_length(const char"); In functions.cpp add \#include "functions. h " and the following code: int string_length(const char *str) return 0 ; In main.cpp add the following below the last cout you added: If f std: j - Compile and run with: - a.out (or a on Windows) - a.out hello (or a hello on Windows) - You should see something like this: - Of course the length is wrong because the string_length() function is just stubbed, but stop here to test and commit. This is a proper programming process. You now know you have a working architecture so it's time to add and commit again. It's also a good time to push. Do all that. - Now working in main.cpp and functions.cpp and functions.h modify your program so it works like the following examples (next page). - You must use a loop of some sort in string_length0 and may not use any 'magic' library function to tell you the string length. In other words, make a while loop to count the characters in the array and return that count. DO NOT USE A FOR LOOP. See hest practices for why. - Other than having to use a while loop in string_length0, code whatever else you think you need to make your program work EXACTLY like the examples below (one exception for Windows users, if your program name includes the path in the length, ignore it it's a Windows things not worth fixing) - Note that your program has to work for any number of parameters from 0 to n where n is any number. Header Files You must use proper header files and file structure in all programs in this class. Failure to use proper header files will result in a substantially reduced grade, up to and including a 0 . Follow these rules like a checklist in all code you write in ClC+4 - One set of ,ccp and h per module. - You can have a h without a .cpp, but never a cpp without a h - main cpp contains only the main() function and it is your application driver function. Never place any other functions in main.cpp. - When making a functions module, include only functions that are conceptually related in some way. For excample a "printing" module, or a "math" module. - When making a class: one class one class cpp with one class h. No more, no less. - Each cpp file has one-and-only-one directive, the Ainclude for its header. - All other directives for a module go in that modules header. - Never write code in a header flle. - Never include cpp files. There is one exception, it deals with templates, but if you are doing that, you will know when it's okay. - Each header file contains exactly what its cpp file needs to stand alone, nothing more, and nothing less. This enforces loose coupling. Grading: Your grade will be graded primarily on exactness to detail and specifications, architecture, and coding logic. You will also be graded on your repo with the following guidelines: - Failure to commit often, small, and smart will result in an automatic 10% penalty regardless of your code quality. - Any stray files in your repo will result in an automatic - 10\% penalty regardless of your code quality. - If you do not have proper comment headers and/or do not use the Write Submission feature (not the comment section), and/or do not submit your link correctly, it's an automatic 10% penalty regardless of your code quality. - Failure to use the correct branch in your repo (main) will result in an automatic 5% penalty regardless of your code quality. Notice that if your repos and repo usage is not correct, it is impossible to achieve an A in this class. It is also impossible to even pass a job interview, let alone work as a professional developer, if you do not master git and GitHub. This is an essential and mandatory skill in this field. Submission: When you are ready for grading. use the write submission feature in Blackboard and submit your repo's link. If you need to fix/change something after you submit but before it's graded, just fix/change it and push again. Do not re-submit the assignment before getting a grade. Only re-submit after you get a grade and want a re-grading

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions