HOMEWORK SUBMIT system: C++ Homework SUBMISSION for C++ Assignments for Jacobson
square.cpp pattern.cpp
square.cpp Page 298 - 22. Square Display pattern.cpp Page 298 - 23. Pattern Display
The program file names will be:
square.cpp Page 298 - 22. Square Display pattern.cpp Page 298 - 23. Pattern Display
// Note the weblab.uni.edu syntax for // #include <iostream> differs from // #include <math.h> for the .h suffix. #include <iostream> #include <math.h> using namespace std; int main() { double x; cout << "Enter a value for x: "; cin >> x; cout << "\nSquare root of " << x << " is " << sqrt(x) << endl; }
Programming Challenge of the Day - Feb 3rd, 2016 Page 294 of the textbook. 2. Characters for the ASCII Codes Write a program that uses a loop to display the characters for the ASCII codes 0 through 127. Display 16 characters on each line. Note: Oops, I changed it to display 8 characters per line in the SASP. Solve A Simpler Problem = SASP
// SASP = Solve A Simpler Problem - Wednesday, Feb 3rd, 2016 // Simpler Problem is: Output the number 0, 1, 2, 3, ..., 126, 127 // 8 numbers per line. // Example of the output pattern: // 0 1 2 3 4 5 6 7 // 8 9 10 11 12 13 14 15 // 16 17 18 19 20 21 22 23 // 24 25 26 27 28 29 30 31 // 32 ... // ... // ... 119 // 120 121 122 123 124 125 126 127 #include <iostream> using namespace std; int main() { int i; for (i = 0; i <= 127; i++) { if (i % 8 == 0) cout << endl; cout << i << " "; } } Note: Solve the SIMPLEST PROBLEM would be to just write the program to output the numbers 0, 1, 2, ... 126, 127 to the screen. That would be SASP applied to the above SASP. int main() { for (int i = 0; i <= 127; i++) { cout << i << endl; // simplest problem of all, but 128 lines of output! :-( } } Then solve the more complicated problem of getting 8 (or 16) numbers per line.
for (i = 0; i <= 127; i++) { if (i % 8 == 0) // VIP! cout << endl; // This works but it is VERY VERY VERY BAD. cout << i << " "; // Indentation is very important for showing } // the logic of your program!!!
#include <iostream> #include <iomanip> // We will cover iomanip on Friday - see setw(3) below using namespace std; // ------- int main() { int asciiVal; char asciiChar; for (asciiVal = 0; asciiVal <= 127; asciiVal++) { if (asciiVal % 8 == 0) { cout << endl; cout << " ----- " << setw(3) << asciiVal << " "; } asciiChar = asciiVal; cout << asciiChar << " "; } cout << endl << "------------------------------\n\n"; }
----- 0 ----- 8 ----- 16 ----- 24 ----- 32 ! " # $ % & ' ----- 40 ( ) * + , - . / ----- 48 0 1 2 3 4 5 6 7 ----- 56 8 9 : ; < = > ? ----- 64 @ A B C D E F G ----- 72 H I J K L M N O ----- 80 P Q R S T U V W ----- 88 X Y Z [ \ ] ^ _ ----- 96 ` a b c d e f g ----- 104 h i j k l m n o ----- 112 p q r s t u v w ----- 120 x y z { | } ~ ------------------------------
You only care about the Chr and the Dec -
Decimal value is column 1 and Chr is column 4.
As you can see, decimal values 0 to 31 have a DESCRIPTION in the Chr column,
instead of a character like "0" or "9" or "A" or "a" or "$".
for (asciiVal = 32; asciiVal <= 127; asciiVal++) { if (asciiVal % 16 == 0) // SWEET SIXTEEN instead of ELITE EIGHT { ------------- ----------- cout << endl; cout << setw(10) << asciiVal << " ---> "; } ...
ASSIGNMENT: Programming Assignment #2...
See textbook -
22. Square Display and 23. Pattern Display - both on page 298.
Two programs from chapter five of the textbook.
Due on Monday, February 8th by 11:00 am or before...