$24
Course Assignment/Exercise Notation Conventions: Each weekly “assignment” consists of several
“exercises”. Throughout this course I commonly refer to these using an abbreviated notation, where a
form like C1A2E3 would refer to exercise 3 in assignment 2 of the “C/C++ Programming I” course and
C1A2 would refer to the entirety of assignment 2 of that course.
7
Getting Started: Before starting your first assignment you must have the appropriate tools for developing
your software and the best way to get them is to download and install one of the many free integrated
development environment (IDE) packages. These integrate the compiler, editor, and other necessary
tools into a convenient GUI application. Although you are free to use any tools you wish and any
operating system that will support them, I recommend Microsoft’s "Visual Studio Community" for
Windows, "Xcode" for macOS, and "Code::Blocks" for Linux. Information on obtaining, installing, and
using them is available in the appropriate version of the "Using the … IDE" course document, a link to
which is located on the "Assignments" page of the course website. I am sorry but I do not have
information on other IDE’s or operating systems.
17
Source Code Files: Header Files and Implementation Files: “Source code” files contain the code
necessary for a program to be built without errors and are divided into the two categories “header” files
(.h, etc.) and “implementation” files (.c, .cpp, etc.). Not all programs require header files but at least
one implementation file is always required. Header files are designed to be included in other files using
the #include directive but implementation files are not. By placing items that might be needed by
23 multiple other files in header files and including them in those files the bad practice of literally
duplicating the needed items in each file can be avoided. Because of their multiple usages, however,
header files must never contain anything that will result in an error if more than one file includes them.
Files containing data that your program reads or writes are not considered source code files but are
instead “data files”.
28
Although some of the following terminology has not yet been discussed in this course it is placed here
for completeness and for future reference: Header files typically contain things like macro definitions,
inline function definitions, function prototypes, referencing declarations, typedefs, class/structure/union
descriptions, and templates, although any of these that will only ever be needed by one specific
implementation file may be placed in that file instead. Header files must not contain non-inline function
definitions or defining variable declarations; these must be placed in implementation files instead. The
header files that are supplied with a compiler provide the information it needs to properly compile code
that uses the various functions, macros, and data types available in the compiler’s libraries.
37
Exercise Submission Procedure: Get an exercise to work first on your computer, then submit it to the
“assignment checker” and wait for the results to be returned. If there are any errors or warnings make
the appropriate corrections and resubmit, repeating as necessary until all issues are corrected.
Additional details are provided in each exercise and the course document titled “How to Prepare and
Submit Assignments”.
Assume language standards compliance and any necessary standard library support unless stated otherwise. These are not trick questions and there is only one correct answer. Basing an answer on actual testing is risky. Place your answers in a plain text “quiz file” named C1A1E0_Quiz.txt formatted as:
a “Non-Code” Title Block, an empty line, then the answers:
A
C etc.
Personalized C1A1 requirements exclusively for Jose Medrano (U09845800)
C/C++ Programming I (Section 174273)
C1A1E1 (7 points – C++ Program)
Exclude any existing source code files that may already be in your IDE project and add a new one,
naming it C1A1E1_main.cpp. Write your program in that file.
4
Note 1.7 of the course book illustrates how some expressions can be written more compactly, where the
most compact form is defined as the form containing the fewest non-whitespace characters. For
7 example, x = x + y should always instead be written as x += y. The most compact form is always the
most appropriate form and is the only form allowed in this course.
Note 2.7 illustrates the most appropriate way to negate (change the sign of) the value of a variable. For
example, unconditionally negating the current value of x should always be written as x = -x, never in
any other way. It is the only form allowed in this course.
13
Write a program that displays the most appropriate form of each of the following 14 expressions with
respect to the updated value of integer variable ax. Do not attempt to actually evaluate the
expressions. Of these expressions:
• Two are already in their most appropriate form.
• Two have two most appropriate forms.
• Four only involve the negation of the value of ax.
20
ax = ax + bx
ax = ax / -bx
ax = bx / ax
ax = -1 * ax
ax = -ax * ax
ax = -bx * ax
ax = bx - ax
ax = 2 + ax
ax = 1 + ax
ax = ax - 37
ax = ax - 1
ax *= -1
ax /= -1
ax = 0 - ax
35
Display each expression on a separate line along with its most appropriate form with double-quotes
around each. Be sure to display the words should be after the original expression and the word or
between the most appropriate forms if there is more than one. Here is an example of the required
output format for three hypothetical expressions:
40
"abc = def - ghi" should be "abc = def - ghi"
"abc = abc * def" should be "abc *= def"
"abc += 1" should be "++abc" or "abc++"
44
• The code in your main function must start with cout << or std::cout << on a line by itself.
• Do not use cout or the << operator more than once.
• Do not declare any variables.
48
49
Submitting your solution
`Send an empty-body email to the assignment checker with the subject line C1A1E1_174273_U09845800
and with your source code file attached.
Personalized C1A1 requirements exclusively for Jose Medrano (U09845800)
C/C++ Programming I (Section 174273)
See the course document titled “How to Prepare and Submit Assignments” for additional exercise
formatting, submission, and assignment checker requirements.
55
56
Hints:
See notes 1.5, 1.7, and 2.7.
Exclude any existing source code files that may already be in your IDE project and add a new one,
naming it C1A1E2_main.c. Write a program in that file to display the exact text below using printf:
4
In C/C++ the case of letters is significant.
main is where program execution begins.
A semicolon terminates most statements.
10% of "nothing" is 100% of "nothing".
Use \n to cause a newline; use \t to cause a tab.
Use \a to cause a beep (only in some cases)!
11
Your program must:
1. not call printf more than once.
2. not use the underlying numeric value of any character.
3. not use the %c or %s conversion specifications.
16
17
Submitting your solution
`Send an empty-body email to the assignment checker with the subject line C1A1E2_174273_U09845800
and with your source code file attached.
See the course document titled “How to Prepare and Submit Assignments” for additional exercise
formatting, submission, and assignment checker requirements.
23
24
Hints:
To display a percent character located within a printf control string (the control string is the first
argument of printf) use two percent characters together. To represent a backslash character in any
string use two backslash characters together. The compiler automatically concatenates multiple string
literals separated only by zero or more whitespaces into one string, including string literals on separate
lines.