Its an assignment from introduction of C++

profilearju___
p360.4.ccctcLIVE.pdf

CISP360 Structured Programming in C++

Cat, Cot, Cap Temperature Calculator (ccctc) Professor Caleb Fowler

February 2, 2021

Problem. Your friend has asked you to help them with a project. He needs to convert a Fahrenheit temperature to either Celsius, Kelvin or Rankine temperature scales. However, your friend is a bit - odd. He needs this to apply to only three objects: a cat, a cot and a cap. Each object has a valid temperature range for his calculations.

Requirements.

• Prompt for the object to calculate the temperature for. Note: This is NOT a menu! The client is expected to enter the proper words.

• Ask for the temperature of the object in Fahrenheit. Check to see if it’s in the proper range.

• Create a menu of valid temperature scales to select from. Selecting the scale option will immediately display the converted tempera- ture. Include an option to calculate the temperature for ALL the options.

• Re-prompt if incorrect data was entered. Keep re-prompting until the client get’s it right.

• No global variables or global variable look a-likes. • Use white-space and comments to make your code more readable. • Put a Source File Header at the top of your source file. • Include a void ProgramGreeting() function. This will run auto-

matically once when the program first starts. This function should display (on individual lines): – A welcome message. – Your name (as author). – The date this assignment is due. Format this as MonthName

day, year. Example: June 30, 1988. • Do not your c (.h) style libraries. Use c++ libraries instead. • Your program must compile in C++ on Ubuntu. • Your program must generate logically correct output.

Folsom Lake College

cat, cot, cap temperature calculator (ccctc) 2

Valid temperature ranges for the 3 items.

Specifications.

� // Specification C1 – Only Valid Words We only want to accept valid words cat, cap, cot no matter how they are spelled (ie Cat, CAT, caT all Ok too).

� // Specification C2 – Temp Scale Menu This menu shows us what temperatures we can convert to. This can be a numeric menu.

� // Specification C3 – Valid Scale Menu Check Only allow valid menu options to be entered. Give the client feed- back if it’s wrong and re-prompt.

� // Specification B1 – Floats for Temps Allow the client to enter a decimal temperature.

� // Specification B2 – Valid Temps Only Make sure the user can input the temperatures only within a valid range. If out of range, tell them (too high, too low) and re-prompt. Temperatures must be valid floats with in the proper range. We can accept an error of less than 0.2 degrees. Example: a valid tem- perature for a cat will be 102.2, but 102.3 will not.

� // Specification B3 - Auto Variable Type Use the auto variable type at least once in the program.

� // Specification A1 – Sophisticated Word Check Your validation check can only test against 3 lowercase words: cat, cot, cop. Yet, somehow, you must still address the issue of our client entering any combination of upper and lower case letters. See discussion below for more information.

� // Specification A2 – Another Thing

cat, cot, cap temperature calculator (ccctc) 3

Add another thing (dog as well as cat, etc etc). Modify the pro- gram to process it correctly.

� // Specification A3 – Another Temperature Scale Add another temperature scale. You will be amazed at how many other scales there are out there.

Rubric.

Element Points Code Compiles 15 Code Runs and generates correct output 10 Source File Header 5 No .h libraries 5 Program Greeting 5 Each of the 3 ’C’ Specifications 5 (15) Bonus for all ’C’ Specifications 5 Each of the 3 ’B’ Specifications 5 (15) Bonus for all ’B’ Specifications 5 Each of the 3 ’A’ Specifications 5 (15) Bonus for all ’A’ Specifications 5 Total Points 100

Late Penalty: -10 points

Sample Run.

Use the same data to check your answers with mine. Figure 1 shows a sample run with sample data.

Discussion. You will need to research the formula’s to convert Fahrenheit

temperatures to Celsius, Kelvin and Rankine scales. Wikipedia is one easy to use source.

It’s a huge pain to check all the ways we could spell the input words. Student’s commonly enumerate every single possible spelling in one gigantic compound if statement. That’s the brute force ap- proach. It works but it’s difficult to maintain. There is a more so- phisticated approach. One way to simplify it is to convert all input strings to lower case, then test against the lower case word only. This is called a canonical form of input and it will make your life easier.

Another thing you can do to make your life easier is to look for patterns in the input. In this case, all the valid input words begin with ‘c‘. So one check we could make is look at the first letter of the input string. If it’s not a ‘c‘ then we know the word can‘t possibly be

cat, cot, cap temperature calculator (ccctc) 4

Figure 1: Sample program run.

correct. Google extracting characters from strings if you aren’t sure how to do this.

Due Date.

This assignment is due by 11:59 PM on Sunday on the date on the calendar in Canvas. All the assignments are open the first day of class and you can begin working on them immediately. I encourage you to start sooner rather than later with your homework, these always seem to take longer than you think.

Late Work.

If you miss the due date and time specified above, your work is late. Canvas records the date and time your homework upload COM- PLETES. Late work is still acceptable, but it suffers a 1 letter grade penalty. You may turn late work in up until MONDAY 11:59 PM AF- TER THE ASSIGNMENT WAS DUE. That is, you have 1 day to turn your work in - after that the Canvas drop box closes. Once Canvas closes I will not accept an assignment.

Pro-Tip: Get a bare bones copy of your code running and turn it in. Then go ahead and modify it, fix it and whatnot. Upload it with the same name when you finish. That way, if something unexpected happens, you have some working code turned in. Risk management, class, risk management. 1 1 If you really want to go pro, get some

sort of version control system running (like Git).

cat, cot, cap temperature calculator (ccctc) 5

How to Turn in your Homework. I ONLY accept homework through the Canvas Dropbox. Do not add it to the submission comments or email it to me - I will not accept it. Turn homework in by uploading to the appropriate Canvas Dropbox folder. Save your homework as a .cpp file. Don’t zip or otherwise compress your files. Do NOT split your file up into multiple files. I know that is a standard industry practice, but it just get’s in the way for this class.

Create a file with the following naming format: W12345678.cpp (your w number). This allows me to sort the class in alphabetical order - don’t stand out here! If you are having trouble submitting the assignment, email me immediately. Don’t change your filename if you make multiple submissions - Canvas will keep track of them and download the latest one by default.

Style Guide.

All programs you write MUST have the following code and/or com- ments. Again, I look for these elements with my scripts, you want me to find them.

Comments. Use white space and comments to make your code more readable.

I run a program called cloc (count lines of code) which actually looks for this stuff.

End of line comments are only permitted with variable declara- tions. Full line comments are used everywhere else.

Specification Comments. Specifications are bundled into groups: "A", "B", "C". You must

meet the specifications of the lowest group before I will count the specifications for the highest group. For example, you must meet the "B" specifications before I will count the "A" specifications. If you miss one element of a specification bundle, that is the grade you will get for the assignment - regardless of how much extra work you do.

Use whole line comments for Specifications. Put the comment on the line above the start of the code implementing the Specification. If the same Specification code appears in more than 1 place, only com- ment the first place that Specification code appears. Number your Specifications according to the specification bundle and the specific specification you are using, also provide a very short description. DO NOT BUNCH ALL YOUR SPECIFICATIONS AT THE TOP OF THE SOURCE FILE. Example specification comment:

cat, cot, cap temperature calculator (ccctc) 6

// Specification A2 - Display variables

Your code to do this starts here;

It’s very important to get the specifications down correctly. If your specification code isn’t commented, it doesn’t count. I use the grep trick to find your specification code. Proper documentation is part of the solution, just like actually coding the solution is.

Compiler Warnings. Compiler warnings are a potential problem. They are not tolerated

in the production environment. In CISP 360 you can have them. I will deduct a small number of points. CISP 400 - I will deduct lots of points if compiler warnings appear. Make sure you compile with -Wall option. This is how you spot them.

C++ Libraries. We are coding in C++, not C. Therefore, you must use the C++

libraries. The only time you can use the C libraries is if they haven’t been ported to C++ (very, very rare).

Non-Standard Language Extensions. Some compilers support unapproved extensions to the C++ syn-

tax. These extensions are unacceptable. Unsupported extensions are compiler specific and non-portable. Do not use them in your pro- grams.

Program Greeting. Display a program greeting as soon as the program runs. This is a

simple description of what the program does. Example:

// Program Greeting

cout « "Simple program description text here." « endl;

Source File Header. Start your source file with a program header. This includes the

program name, your name, date and this class. I use the grep trick for .cpp (see below) to look for this. I focus on that homework name and display the next 3 lines. Example:

// drake.cpp

// Pat Jones, CISP 413

// 12/34/56

Specifications and Specification Bundles. You document specifications like this: // Specification C1 - Some

stuff

cat, cot, cap temperature calculator (ccctc) 7

You do not need to code them in order. You will probably want to because the specifications get harder as you move up in bundles (not THAT much harder). You also don’t need to worry about the specification comments appearing in order in your code, either.

However, all of a specification bundle must be coded to reach that bundle grade (ie all C bundle to get a C). Partially completed bundles DO NOT COUNT. Say you code all specifications for a B bundle and only 1 for an A bundle (out of 5 for example). The highest grade you would get would be a B because that’s the last bundle you’ve completed.

You can stop at any bundle you want, you just can’t get a higher grade (ex, you code all specifications for bundle B - the best you can get for this homework is a B). This is designed to mirror the work word, the more features your code has, usually, the happier your clients are. This also gives you some control over your grade.

This style guide has more information on the specifics of these comments.

Variables. Constant variables - anytime you have a value which is not sup-

posed to change, that’s a constant. We make it read only with the const keyword and signify it with the ALL CAPS style: const PI = 3.14; We prefer using constants because they make the code easier to read. There are a few situations where we do not usually use them, such as starting a loop at zero. However, if we have that loop end at, say, 33, then it’s a magic number. What’s 33? Who knows? If we use const SIZE = 33; we know what 33 is.

When we have numeric literals appearing in the program we call these magic numbers. We don;t know what they are, but if we change them, the program breaks. hence, magic. Magic numbers are gener- ally frowned upon.

Grep Trick.

Always run your code immediately before your turn it in. I can’t tell you how many times students make ’one small change’ and turn in broken code. It kills me whenever I see this. Don’t kill me.

You can check to see if I will find your specification and feature comments by executing the following command from the command line. If you see your comments on the terminal, then I will see them. If not, I will NOT see them and you will NOT get credit for them.

cat, cot, cap temperature calculator (ccctc) 8

The following will check to see if you have commented your specifi- cations:

grep -i ’specification’ homework.cpp

This will generate the following output. Notice the specifications are numbered to match the specification number in the assignment. This is what I would expect to see for a ’C’ Drake assignment. Note the cd Desktop changes the file location to the desktop - which is where the source file is located.

This is what I would expect to see for an ’A’ level Drake assign- ment.

We can also look at the line(s) after the grep statement. I do this to pay attention to code segments.

grep -i -C 1 ’specification’ aDrake.cpp

We can also use this to look for other sections of your code. The grep command searches for anything withing the single quotes ”,

cat, cot, cap temperature calculator (ccctc) 9

and the -i option makes it case insensitive. This is how I will look for your program greeting:

The grep trick is extremely powerful. Use it often, especially right before you turn in your code. This is the best way I can think of for you to be sure you met all the requirements of the assignment.

Client System.

Your code must compile and run on the client’s system. That will be Ubuntu Desktop Linux, version 18.04. Remember, sourcefile.cpp is YOUR program’s name. I will type the following command to compile your code:

g++ -std=c++14 -g -Wall sourcefile.cpp

If you do not follow this standard it is likely I will detect errors you miss - and grade accordingly. If you choose to develop on an- other system there is a high likelihood your program will fail to compile. You have been warned.

Using the Work of Others.

This is an individual assignment, you may use the Internet and your text to research it, but I expect you to work alone. You may discuss code and the assignment. Copying code from someone else and turning it in as your own is plagiarism. I also consider isomorphic homework to be plagiarism. You are ultimately responsible for your homework, regardless of who may have helped you on it. ProTip: Get a bare bones copy of your

code running and turn it in. Then go ahead and modify it with bonuses and whatnot. Upload it with the same name so it replaces your previous homework. This way, if something comes up or you can’t finish your homework for some reason, you still have something turned in. A "C" is better than a zero. Risk management class, risk management.

Canvas has a built in plagiarism detector. You should strive to generate a green color box. If you submit it and the score is too high, delete it, change your code and resubmit. You are still subject to the due date, however. This does not apply if I have already graded your homework.

Often, you will not be able to change the code to lower the score. In this case, include as a comment with your homework, what you did and why you thought it was ineffective in lowering your score. This shows me something very important - you are paying attention to what you are doing and you are mindful of your plagiarism score.

  • Problem.
  • Requirements.
  • Sample Run.
  • Discussion.
  • Due Date.
  • Late Work.
  • How to Turn in your Homework.
  • Style Guide.
  • Grep Trick.
  • Client System.
  • Using the Work of Others.