If there is one prayer that you should pray/sing every day and every hour, it is the
LORD's prayer (Our FATHER in Heaven prayer)
- Samuel Dominic Chukwuemeka
It is the most powerful prayer.
A pure heart, a clean mind, and a clear conscience is necessary for it.
For in GOD we live, and move, and have our being.
- Acts 17:28
The Joy of a Teacher is the Success of his Students.
- Samuel Dominic Chukwuemeka
I greet you this day,
For My Students, please do the following:
First: Download and install the Microsoft Visual Studio Integrated Development
Environment (IDE), or any suitable IDE for C++
Second: Review the required readings for each module including the Student-Teacher scenarios.
Third: Review the recommended readings for each module.
Fourth: Review the recommended videos and textbooks for each module.
Fifth: Complete the DB (Discussion Board) assignments for each module.
Sixth: Start thinking about your midterm project, final project, and final exam.
Seventh: Review the midterm exam and final exam study guides.
Eighth: Should you have any questions, comments, concerns, areas of improvement, and constructive criticisms;
please attend the weekly Office Hours/Live Sessions and/or contact me via the school's email system.
Ninth: If you are majoring in any IT (Information Technology) field
(especially for women and minorities),
you may want to check the Financial Aid section in any of my websites:
Scholarships or
Scholarships
For My Students and Visitors:
Comments, ideas, areas of improvement, questions, and constructive criticisms are welcome.
For All Those who Seek Peace:
Thank you for visiting.
Samuel Dominic Chukwuemeka (SamDom For Peace) B.Eng., A.A.T, M.Ed., M.S
(1.) Please review the
Rules of Netiquette
(2.) Please be creative.
Please paraphrase in your words as applicable.
(3.) No two posts should discuss the same thing.
Each post should be unique.
This implies that you should review any previous posts before you submit your own post.
(4.) The initial post is due on Thursday of the week for which it is required.
(5.) At least one response to the initial post is due on Saturday of the week for which it is required.
(6.) Only one thread per student is allowed.
Please do not create more than one thread.
Please respond to my comments (as applicable) in the same initial thread.
Please make any repost in the same initial thread.
Besides the Introduction DB (where I am required to welcome each student); usually, I make comments to some posts and some
responses submitted by Thursday of the week that a DB assignment is due.
If I make any comment to your initial post and/or response (submitted by Thursday); then it is very important you address any
concern in my comments.
If you do not understand my comments, please attend the Office Hours/Live Sessions and/or send an email to me and ask for
clarification.
I do not go back-and-forth (responding more than one time) to a student in DB forums.
The essence of DB forums is mainly for student communication and collaboration.
The professor only facilitates and makes few comments as necessary.
Typically, if I make any comment to your post and/or response for any DB assignment besides the Introduction DB,
it means that you need to fix some issues.
It is important you fix those issues to avoid deduction of points.
(7.) You may not do any of the same examples that I did for either a DB post or DB response.
(8.) You may do any of the questions in the Discuss tab as
a substantive post and/or substantive response.
(9.) You may make up your own substantive post and/or substantive response
if it is actually substantive.
However, in this case; it is very important you ask me for prior approval.
You may ask me during the Office Hours/Live Sessions and/or via the school's email.
(10.) You may solve the problems in the Assess tab as a DB assessment (post and response).
Questions in the Assess tab count for both DB post and DB response.
Each question in the Assess tab is to be uniquely done by only one student.
This means that it can be done by more than one student.
However, each post must be unique.
Further: For Textbook Questions in the Assess tab:
(a.) Please submit a clear screenshot of the Question Number and the Question.
(b.) Any question from the textbook in the Assess tab should be done by only one student.
(11.) Sources must be cited accordingly.
You may use: APA (American Psychological Association) style, MLA (Modern Language Association) style, or the
Chicago Manual of Style.
(12.) Please submit clear screenshots.
For all applicable DB posts and responses, please use the Snipping Tool or the Snip & Sketch
on your computer to take clear screenshots
and trim off excess space/irrelevant information from your program code and output.
Then, use the Insert/Edit Image icon on the Blackboard editor to insert the screenshots of your code
and the output.
This is because your colleagues and I should be able to see your code and the output clearly.
Line numbers and all necessary details including the file names are also required.
You may need to increase the font size of your IDE so it is very clear.
You may need to take the screenshots of only the relevant window (the code window).
You may need to take several screenshots.
Also, please ensure you use a clear format for your writings.
Avoid any background colors in the Blackboard Editor.
(13.) Please do not submit an attachment for any DB assignment.
If you do, it will not be clicked. It will not be read. It will not be graded.
Your colleagues and I should be able to see your work directly without opening any attachment.
Any response to such post will not be counted.
Hence clear screenshots are required.
(14.) For all DB responses, please mention the first name of your colleague.
(15.) Provide a substantive response to your colleague.
A substantive response is the response that provides constructive criticism,
alternative approach that gives the same correct output, additional helpful information that will improve the post,
and the correction of any incorrect step and/or output among others.
How would you improve the initial post?
Did you find any errors in the initial post? If you do, please correct the error. Teach your colleague about the error, and
explain to him/her how to fix it. Provide screenshots as applicable.
What new knowledge can your colleague acquire from you based on your response?
Can you solve the initial post using an alternative approach that will give the same correct output?
What real-world examples/applications can you provide based on the initial post? Cite your sources accordingly.
Did your colleague learn anything meaningful from you based on your response to the initial post?
Please focus on the initial post. Do not deviate from the concept/topic in the initial post.
Do not bring up your own unrelated topic/concept.
Teach/Show your colleague something new and meaningful based on the initial post.
Write code examples as applicable, run them, and explain to your colleague.
Substantive responses should include screenshots as applicable.
(16.) Please use at least a size of 14 pt in your writings on the Blackboard Editor, and an acceptable
large font size on all your programs (IDE and output console among others).
(17.) Please proof-read your writings for mechanical accuracy errors.
Any use of "i" attracts deduction of points.
Multiple mechanical accuracy errors will lead to deduction of points.
I understand that this is not an English class. However, you are expected to write well.
(18.) Please make sure that you write comments for any program you submit.
Rule of Thumb for Comments (for academic purposes): Anyone (including those with little or no programming knowledge) should be
able to read your comments and have a basic idea of your program.
Unless written otherwise (for some questions), I am not saying you should write comments for every line of code.
I am asking you to write comments for every code block (section of code).
Do you read my comments? Of course, you should. I provide explanations in my comments.
Does it make sense? Yours should not be different.
A Computer program is a set of instructions given to a computer to perform specific tasks.
A Computer programmer also known as a coder is a person who writes computer programs.
A statement in C++ is an individual instruction of a program.
A Variable is a portion of computer memory for storing a data value.
Identifiers are unique names used to identify variables.
A string is a variable in C++ that contains a collection of characters enclosed in double quotation marks.
Object-oriented Programming (OOP) Language is a programming language that uses objects to accomplish the goals of a computer program.
An Object is anything that can be touched, seen, or used.
These include: data types (it can be used), variables (it can be used),
toolbox controls (it can be seen and used) among others.
An Object is also defined an instance of the class (when you use the class that has been created).
Instantiation is the act of creating an object.
The Behavior of an object includes methods and events.
A Method is an action that an object can perform.
For example: The Exit button can use the $Me.Close()$ method to close an application.
In Object-Oriented Programming, methods are often called procedures
Events are the actions to which an object can respond.
For example: The Click event of the Exit button allows the button to respond to
a mouse click.
Properties are the set of attributes that determine the appearance and behavior of an object.
Access Modifiers specify the level of access classes and class members provide to other classes.
Encapsulation is the combination of fields, properties, methods, and events of an object
in a class(capsule).
In other words, keep all the data and program logic in one place.
Inheritance is the ability to create a new class that reuses, extends, and
modifies/overrides the behavior defined in another class.
The main class whose members are inherited is known as the Base class or Super class
The class that inherits the members of the main class is known as the Derived class or Sub
class
The derived class inherits members of the main class using the Inherits clause.
Abstraction is the hiding away of some details about a program so one can focus on the main
details.
For example, the $PrintForm()$ class in Visual Basic enables one to print a Windows form application at
run time (when the program is running)
There are so many details about the $PrintForm()$ class. However, that is not your concern. Your concern
is to use that class and print a form. So, those details are hidden from you.
Another example: You do not really want to know how the printer was developed. You just want to know how
to use the printer
and print your documents.
Constructors are class methods whose instructions are processed automatically whenever
the class is used to create/instantiate the object.
They are used to initialize the Private variables of the class.
They are always a Sub procedure named New
Declared Elements are programming elements that is defined in a declaration statement.
They include: variables, constants, structures, properties, events, methods/procedures, and classes
among others.
Course using C++ introducing concepts of software development, object-oriented event-driven programming, testing and debugging, simple and complex data types language syntax and semantics. Prerequisite: None.
By the end of this course, you should be able to do the following:
(1.) Demonstrate best practices for designing end-user computing interfaces.
(2.) Discuss software development methodologies.
(3.) Use a programming or a scripting language to solve a problem.
(4.) Discuss significant trends and emerging technologies and their impact on our global society.
machine language, assembly language, low level language, high level language, IDE (Integrated Development Environment), text editor, compiler, development toolchain, linker, program, header file library, white space, braces, curly brackets, semicolon, character input (cin), character output (cout), standard input stream (cin), standard output stream (cout), extraction operator, insertion operator, namespace, standard library, variable, object, function, main function, integer, angle brackets, input/output stream library,
Students will:
(1.) Download and install the Visual Studio IDE or any suitable IDE for C++
(2.) Discuss an overview of the C++ programming langauge.
(3.) Write simple programs in C++
(1.) Textbook Chapter
(2.) Tutorials by cplusplus.com
Information on the C++ language
(www.cplusplus.com/info/)
and
Program Structure
(www.cplusplus.com/doc/tutorial/program_structure/)
(3.) Tutorials by w3schools: C++: C++ HOME to C++ Comments
(www.w3schools.com/cpp/default.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ or Cplusplus in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ or Cplusplus in the search bar and view/read the results.
00000 | 10011110 |
00001 | 11110100 |
00010 | 10011110 |
00011 | 11010100 |
00100 | 10111111 |
00101 | 00000000 |
Teacher: Please look at the code above.
Do you understand that code?
Student: The bunch of zeros and ones?
I have no idea what those mean.
int num1, num2, sumNum;
cin >> num1;
cin >> num2;
sumNum = num1 + num2;
cout << sumNum << endl;
Teacher: What about this code?
Do you understand it?
Student: I do not fully understand it.
However, it makes much sense than the first code?
Teacher: Both codes execute the same tasks.
Ask the user to input those numbers. Add those numbers. Output the sum.
Which code is better?
Student: The second code of course.
Teacher: The first code is the machine code.
It is the machine language.
It is a low level language.
It is the language the computer understands directly without translation.
The second code is the high level language.
It is the language humans can read and understand better.
Hence, there is the need to compile or interpret the high level language to
the machine language
so that computers would do what we want them to do.
C++ is one of the high level languages that we can use.
It is a compiled language.
This means that it is translated into machine language that can be understood directly by the
system.
In that regard, a set of tools are needed.
The set of tools is known as development toolchain
The core of the development toolchain are a compiler and its linker.
The best way to compile and run C++ programs is to use an Integrated Development Environment (IDE).
An IDE typically has several development tools including a text editor and tool to compile C++
programs directly.
For this course, the Microsoft Visual Studio Community Edition (it is free) is highly
recommended.
However, you may choose to use any IDE that you wish.
Here are some free IDEs for C++:
(1.) Microsoft Visual Studio Community Edition 2019 (Windows)
(Highly recommended. The only IDE used for this course.)
(2.) Code::Blocks (Windows, Mac, Linux)
For Windows: download and install the codeblocks-20.03mingw-setup.exe
(3.) Dev-C++ Blog (Windows)
Download and install the setup which includes TDM-GCC 4.9.2 (32bit and 64bit)
We do have online compilers for C++.
The online compilers typically do not require any downloads and installs.
However, please note that all files in the project are required for your Midterm Project, Final Project, and
Final Exam.
In the case where you prefer to use an applicable online IDE, please make sure you download the completed
C++ project (that includes all files).
Here are some free online compilers/IDEs for C++:
(1.) C++ shell (This one is easy to remember:
cpp.sh and gives some options but you cannot upload a file or save the file.)
(2.) C++ Online Compiler, IDE, Editor, Interpreter and REPL (This one allows you to upload files and folders; also allows you
to save your file if you have a Gmail or Facebook account.)
(3.) Online C++ Compiler
(This one allows you to upload a file; also allows you to save your file if you
have a Gmail or Facebook account.)
There are at least three ways to open an existing project.
The first way is my preferred approach.
But, you may choose whatever approach you prefer.
First Way: Clicking the Solution File
Go to the location of your saved project.
Double-click the solution file Introduction.sln
Solution files have .sln file extension.
Depending on the location of your project (when you created your own project):
This PC → Documents → Application Folder → Project/Application
→ Application.sln
Path of the Solution File: This PC → Documents → CPlusPlus → Introduction
→ Introduction.sln
If you do not see the file extension, Click the View tab and check the box: File name extensions in order
to see the file extension.
Second Way: Open Visual Studio Solution from Recent Project
Click the solution file from the recent projects
Third Way: Open Visual Studio Solution from Project
Open a project or solution.
As seen from the pictures:
Comments in the Visual Studio IDE is green in color. We shall keep it that way.
Comments in other IDEs might be different colors.
Student: Can you change the comments to display a different color?
Teacher: Yes Sir, you can.
Student: How do I do so, Sir?
Teacher: You do realize that if you would change it, the change would be for all the
programs you develop with
the Visual Studio IDE. It would not just be for C++. It would also be for C#.
Changing the color of comments would be applied to the entire Visual Studio IDE.
Student: I understand. How do I change the color of the comments?
Teacher: Here are the steps.
First:
Second:
Teacher: In the second picture, you can change the color by selecting from the
dropdown menu.
If you do not like the colors you see there, you can add your own custom color.
However, please leave the default color for all work done in this course.
Comments are required for any program you write in this course.
Rule of Thumb for writing comments: Anyone should be able to read your comments and have
a basic understanding
of the program.
A single-line comment is denoted by two forward slashes.
A multi-line comment also known as a block comment begins with a forward slash and
an asterisk, and ends with an asterisk and a forward slash in that order.
For this course: I shall be using the Second Approach: Line 9 of Step 13 image.
I prefer that approach.
You may use the First Approach if you wish.
Based on the Second Way (Second Approach):
Line 5: #include <iostream>
C++ has a lot of libraries including the Input/Output Stream Library
# is the preprocessor directive
include means that you have to include that library
<iostream> is the Input/Output Stream Library that is included
It allows the program to display an output using the cout (standard output stream)
command
< and > are angle brackets.
#include <iostream> means that the program should look for the iostream library in the directory of the
standard libraries
The program can also compile/run with this command: #include "iostream". You may want to test it.
#include "iostream" means that the program should look for the iostream library in the current
directory first.
If the file is not there, then look in the directory of the standard libraries.
Student: Are there some programs that would not run if the #include "iostream" is
written?
Teacher: You asked a good question.
Yes, there are.
However, generally, we use the angle brackets.
using namespace std;
std is the standard library
using namespace std means that the names from the standard library for variables and
objects can be used.
This implies that we do not have to add std:: (as seen in the First Approach)
int main()
int means an integer
main is the name
The parenthesis, () indicates that it is a function.
If there was something inside the parenthesis, it would be an argument.
However, in this case; there is no argument because the parenthesis is empty.
main()
means a a main function
Every C++ program has a main function
The main function has opening, { and ending, } braces (curly brackets)
Any code inside those braces will be executed.
cout
is the standard output stream
It is the command that displays the message, THANK GOD.
\n indicates the new line escape sequence. (Please review the images above where we used
it and where we did not use it)
For more escape sequences, please review:
Escape Sequences
(https://docs.microsoft.com/en-us/cpp/c-language/escape-sequences?view=vs-2019)
<< is the Insertion operator
$;$ is a semicolon
Every C++ statement ends with a semicolon
C++ ignores whitespaces.
Lines #7 - #10 of Step 13 image can also be written as:
int main(){cout << "THANK GOD\n";}
The program will still run if it is written that way.
However, it is better to write organized line-by-line code.
If there is any issue, it is easier to locate that error by the line numbers.
We can also use void main() instead of int main()
The program will still display the output, THANK GOD.
Student: When do we have to use int versus void for the main function?
Teacher: Good question.
If we want the function to return a value, we use the int main() and specify the
value to return
If we do not want the function to return any value, we use the void main()
Student: But, you just said that if we used void main(), the message will still be
displayed.
Is the message not a value?
Teacher: The message is not a value...technically.
This is what I mean:
First:
Second:
Teacher: Because we used void main() in the second image, the code did not build.
It resulted in build errors because void does not return any value.
So, we do not use the return keyword with the void main function.
Student: Okay, I understand it.
But, that leads me to another question.
Why would you display $7$ but return $0$?
What is the need for the return $0$?
Can the program run without it?
Teacher: Good question.
Every function is expected to return a value. We shall discuss functions in-depth later.
The main function actually returns $0$ whether you write it or not...if the program runs
efficiently
In other words, the compiler/IDE puts it implicitly even if you do not specify it
explicitly.
However, it is standard practice to always include it for any main function for which you
want an output to be displayed.
Going forward, we shall include it.
Student: How do you know the IDE includes it implicitly even if we do not include it
explicitly?
Teacher: Let us see:
Third:
Teacher: So, whether you include the return $0$ or not; the main function will return
$0$
Student: Okay.
You inserted the new line escape sequence because you wanted a new line after the result,
$7$
The program will still run even if you did not insert the new line.
Is that right?
Teacher: That is correct.
The new line was inserted to make the output to "stand out".
Student: What if we returned a value other than $0$?
Say, return a value, $12$
Would it work?
Teacher: Yes, it will work.
However, that is not the standard practice.
Here is the output of your question:
Fourth:
Student: Are there other functions where we would not return $0$?
Teacher: Yes, Sir.
For user-defined functions, we can return whatever we want it to be.
For the main function, we have to return $0$
Student: Would you take off points if we do not include the return $0$?
Teacher: I will not. However, it is the standard practice to include it in the main
function.
The executable file (.exe file extension) is the single file that:
(1.) runs the entire program inside the project folder
(2.) also runs the entire program outside the project folder.
The executable file and the entire project folder (that also includes the executable file) is
required for your Midterm Project and the Final Project (as applicable)
Let us first locate the executable file.
Path of the Executable File: This PC → Documents → CPlusPlus →
Introduction → Debug → Introduction.exe
As you can see, the executable file is located inside the project folder.
Double-click it to run it.
What do you notice?
Did it run? or Did it run and close automatically?
This is what we need to do to make it run and stay, until we close it.
Right before the return statement in the program, we need to add this command/code:
system("pause");
Open the solution file and add this code.
This will stop the executable file from closing automatically.
Go ahead and close the project.
Open the executable file and try and run it.
Then copy the executable file and paste it in another location say the Downloads folder or on your Desktop, and run it.
I should be able to run your executable file inside and outside your project folder and I expect it to run successfully.
Please attend the Office Hours/Live Sessions if you have any questions.
Let us review more code examples. Run these codes and review the output.
// Example 1: Write two different sentences on the same line
#include <iostream>
using namespace std;
int main()
{
cout << "C++ is a programming language. It was developed by Bjarne Stroustrup.\n";
return 0;
}
// Example 2: Write two different sentences on two different lines using two cout commands
// First Method
// cout means standard output stream
#include <iostream>
using namespace std;
int main()
{
cout << "And now these three remain: faith, hope, and love. \n";
cout << "But the greatest of these is love.\n";
return 0;
}
// Example 3: Write two different sentences on two different lines using two endl commands
// Second Method
// endl means end line
#include <iostream>
using namespace std;
int main()
{
cout << "And now these three remain: faith, hope, and love." << endl;
cout << "But the greatest of these is love." << endl";
return 0;
}
Teacher: Do you see the difference between the First Method and the Second Method in
the examples above?
Student: Yes Sir. Which one is the better method?
Teacher: The First Method, of course.
Student: Why is that?...speaking like an American 😊😊😊
Teacher: Because you can use the First Method with only one cout command to write the
two sentences on two
lines.
You cannot do the same with the Second Method.
Further, you can insert blank lines easily with the First Method.
See below:
// Example 4: Write two different sentences using one cout command
#include <iostream>
using namespace std;
int main()
{
cout << "And now these three remain: faith, hope, and love. \nBut
the greatest of these is love.\n";
return 0;
}
Teacher: Did you notice there is no space between the new line escape sequence and
the first letter of
the second sentence?
Student: Yes, I do.
What if we put a space between them?
Teacher: There would be a space in the second line before that first letter. It is an
unnecessary space.
This means that the second sentence would not be aligned with the first sentence.
Try it, run it, and see the result.
Let us look at this example.
// Example 5: Write two different sentences using one cout command
// But insert a blank line between the first line and the second line.
#include <iostream>
using namespace std;
int main()
{
cout << "And now these three remain: faith, hope, and love.
\n\nBut the greatest of these is love.\n";
return 0;
}
(1.) Discuss a brief history of C++.
(2.) Discuss the versions of C++ including any significant change made for each version.
(3.) Discuss any console application developed with C++.
(4.) Discuss any desktop application developed with C++.
(5.) Discuss any web application developed with C++.
(6.) Discuss any mobile application developed with C++.
(7.) Discuss any IDE for C++ including the advantages and disadvantages.
(8.) Explain using appropriate examples, any three new terms learned in this module.
(9.) Compare any three features of C++ with any similar object-oriented language.
(10.) Contrast any three features of C++ with any similar object-oriented language.
(1.) Include any missing gaps in the history of C++.
(2.) Include any missing gaps in the versions of C++.
(3.) Discuss an additional console application developed with C++.
(4.) Discuss an additional desktop application developed with C++.
(5.) Discuss an additional web application developed with C++.
(6.) Discuss any mobile application developed with C++.
(7.) Discuss any IDE for C++. Include the advantages and disadvantages.
(8.) Add to the post of the student who explained any three new terms learned in this module.
(9.) Add to the post of the student who compared three features of C++ with another
object-oriented langauge.
(10.) Add to the post of the student who contrasted three features of C++ with another
object-oriented langauge.
(11.) Provide any of these if it is lacking in any DB post that solved any question in the
Assess tab of this module: Well-written comments; another approach/method to solving the
question; any additional relevant details; etc.
(12.) Review the post (Discuss Questions and Assess Questions) done by your colleagues.
If your colleague developed a console application for a program, develop a desktop application for the same program.
If your colleague developed a desktop application for a program, develop a console application for the same program.
(1.) Textbook: Question (32.) on Page 113
(2.) Write two different sentences on two different lines.
Insert a blank line between the first line and the second line.
Do NOT use the escape sequence.
(3.) Develop a desktop application titled: Introduction
The application should include three buttons: the About button, the Clear button, and the
Exit button.
When a user opens the application, it should display a blank page and the three buttons.
When the user clicks the About button, these information should be displayed:
(a.) Your picture
(b.) A brief summary of you. Write at least three sentences about yourself.
(c.) One sentence about the course and your major/program.
(d.) One sentence about the course expectations/accomplishments. What is your expectation about the course? What
do you intend to accomplish at the end of the course?
(e.) Any other thing you would like us to know about you.
When a user clicks the Clear button, the page should be blank.
When a user clicks the Exit button, the application should close.
I am more interested in the functionality.
However, I am also interested in the design/graphics/aesthetics.
Make a good design.
vary, variable, identifier, data type, data value, value, container, ASCII (American Standard Code for Information Exchange), character (char), signed character, integer (int), signed integer, unsigned integer, short int, long int, long long int, float, double, long double, bool, void, decltype (nullptr), size, storage, precision
Students will:
(1.) Discuss the meaning of variables in C++
(2.) Discuss the data types in C++
(3.) Discuss the rules for using identifiers.
(4.) Write C++ programs that involves the use of variables and data types.
(1.) Textbook Chapter
(2.) Tutorials by cplusplus.com:
Variables and types to Constants
(www.cplusplus.com/doc/tutorial/variables/)
(3.) Tutorials by w3schools:
C++ Variablesto C++ Data Types
(www.w3schools.com/cpp/cpp_variables.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Variables and/or C++ Data Types in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Variables and/or C++ Data Types in the search bar and view/read the results.
A Variable is a portion of computer memory for storing a data value.
Because a variable stores a data value, it is important to identify the type of data value it
stores.
This implies that any variable is associated with a data type.
The data type describes the type of data value stored by the variable.
What type of data is being stored? Are they numeric (numbers), non-numeric
(letters/characters/words), etc.?
As noted with the word: variable, any value stored by it can vary (can
change).
A variable is created/declared in C++ by specifying the data type associated with it and
assigning it to a value.
We declare a variable this way:
datatype variable = value
The equal sign is the assignment statement.
In other words, you assign something in C++ using the equal sign.
Let us review the main data types in C++.
Data Type | Declaration | Size | Description |
---|---|---|---|
Character | char | 1 byte (8 bits) |
Only a single character/letter is stored. The decimal values of ASCII characters/values are also stored. NOTE: If you intend to use the decimal values of ASCII characters/values, you must declare it with the char data type and the decimal value should not be included in quotation marks. |
Integer (Byte) | byte | 1 byte (8 bits) | Integers from -128 to 127 are stored |
Integer (Short) | short | 2 bytes (16 bits) | Integers from -32,768 to 32,767 are stored |
Integer (Integer) | int | 4 bytes (32 bits) | Integers from -2,147,483,648 to 2,147,483,647 are stored |
Integer (Long) | long | 8 bytes (64 bits) |
Integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 are stored NOTE: End any integer declared with the long data type with an uppercase L |
Floating-point | float, double | float: Whole numbers and decimals are stored. Up to 7 decimal places are stored. |
double: Whole numbers and decimals are stored. Up to 15 decimal places are stored. |
Boolean | bool |
0 = false, 1 = true Make the connection with electronic devices. $0$ = Off; $1$ = On |
Only false and true values are stored Displays as 0 and 1 respectively |
Void | void | No storage | |
Null pointer | decltype(nullptr) |
Here is the
Complete description of these data types, sizes, and precision
(https://www.cplusplus.com/doc/tutorial/variables/)
C++ variables are identified with unique names known as idenfiers.
It is important to use identifiers that are meaningful and descriptive.
Anyone reviewing your program should not have to guess the meaning of your variable.
As you can see (based on the image below: Variables, Data Types, Values (Code)):
The variables I used in that example are meaningful and descriptive
Those variables are:
state to denote the State of Ohio, OH
numState to denote the number of the State of Ohio in an alphabetical listing of the
state names
povertyRate to denote the poverty rate of Ohions according to the $2000$ census data
landArea to denote the land area of the Ohio according to the $2000$ census data
motto to denote the motto and seal of the Great State of Ohio
ismottoTrue to denote the Boolean data type if the motto is true
Even without the comments, you already have an idea of the meaning of my variables.
I should not have to guess the meaning of your variables.
Naming Variables
Variable names:
(1.) Can be single letters (please avoid unless if used in loops)
(2.) Can contain a combination of letters, digits, and underscores but must not begin
with a number.
It may begin with a letter or an underscore.
(a.) Please avoid underscores
Avoid underscores even if the variable name does not begin with an underscore.
(b.) Use a combination of letters and digits such as:
num1 to represent the first number
variable1 to represent the first number
(3.) Can contain only letters but must not be any of the reserved keywords.
The reserved keywords are:
alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break, case, catch, char,
char16_t, char32_t, class, compl, const, constexpr, const_cast, continue, decltype, default, delete,
do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if,
inline, int, long, mutable, namespace, new, noexcept, not, not_eq, nullptr, operator, or, or_eq, private,
protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_assert,
static_cast, struct, switch, template, this, thread_local, throw, true, try, typedef, typeid, typename,
union, unsigned, using, virtual, void, volatile, wchar_t, while, xor, xor_eq
(a.) The letters can be Camel case (similar to the hump of a camel) such as:
firstVariable...the V is the hump
In Camel casing letters: two letters are merged as one; the first letter of the second word is
an uppercase
letter while all other letters are lower case letters.
In firstVariable, V is uppercase; all other letters are lower case
(b.) The letters can be Pascal case such as FirstVariable
In Pascal casing, two letters are merged as one; the first letter of the first word and the
first letter of the
second word are uppercase letters while all other letters are lower case letters.
In FirstVariable, F and V are uppercase; all other letters are lowercase.
(c.) uppercase letters (please avoid...it denotes someone who is yelling)
(d.) lowercase letters (okay, but try to avoid)
Student: What if you have three words?
How do you write it in Camel case? Pascal case?
Teacher: Say we want to write the variable, first arithmetic sequence
Camel case: firstArithmeticSequence...A and S are the only uppercase
Pascal case: FirstArithmeticSequence...F, A, S are the only uppercase
In this course, for all applicable variables; please use:
(i.) A combination of letters and digits such as num1 OR
(ii.) Camel case letters such as firstNumber OR
(iii.) Pascal case letters such as FirstNumber
***We shall use single characters when we write condtiions for Iteration statements/Loops
because it is
easier to use single characters in such cases. We shall see examples when we discuss loops.
However, feel free not to use it if you wish.***
(4.) Cannot contain whitespaces or special characters.
The special characters are all the non-numeric and non-alphabet characters on your keyboard such
as ~ (tilde), !(exclamation), @ (asperand), # (hash), $ (dollar), % (percent), ^ (caret), & (ampersand), *
(asterisk).
A whitespace is a horizontal or vertical space.
For example: myNum has no whitespace; but my Num has a whitespace.
Variable names cannot contain whitespaces.
Hence: myNum is acceptable, but my Num is not acceptable.
Declaring Read-Only Variables: Use the const keyword (constant keyword)
As we have learned, a variable vary. The value changes.
However, read-only variables do not change.
Sometimes, we need these kind of variables.
We have to create/declare them using the const keyword.
For example, if we want to use the approximate value of pi as $3.142$ rather than using the
exact value, we can declare it as:
const int $piValue = 3.142$
This means that the variable, piValue is a read-only variable
It will not change it's value.
Student: May you please give code examples?
Teacher: Sure.
Let us review these two examples.
Line #18: the variable piValue2 cannot be changed because it was declared as a read-only
variable (using the const keyword)
(5.) Are case sensitive.
These are all different variables:
firstresult (lowercase), firstResult (Camel case), FirstResult (Pascal case), Firstresult,
FIRSTRESULT (uppercase),
first_result (snake case)
Let us review more variable examples in C++
A variable can store the number, say 5 in a line of code; and the same variable can store a different number, say 7
in another line of code.
So, the values stored by a variable can change.
An example with integers:
An example with strings:
Variables, Data Types, Values:
(1.) Using at least five complete sentences and at least three different variables and data types,
write a program of the summary of what you learned in this module.
(2.) Write a program of a short story or a poem using at least five sentences and
at least three different variables and data types.
(3.) Write a program of a short story, a poem, or drama using at least five sentences, the same variable,
and at least three different data types.
(4.) To be done by only one student on a first-come first-served basis
Assume you have three initials.
Write a program that declares variables to hold your three initials.
Display the three initials with a period following each one, for example: $S.D.C$
(5.) Review the output of the example code of: Variables, Data Types, Values.
The user wants the last sentence to be true rather than 1
What does that say about Boolean data types?
What are the only values that can be assigned to it?
What are the only values that can be returned?
What does each return value indicate based on the assigned value?
(6.) Review the example code of: Variables, Data Types, Values.
Look at Line Numbers #39 and #40
Both outputs are displayed in new lines. However, they were written differently.
Explain the difference.
What is the plus sign on Line #40 called?
( Hint: If the data type was not a string, would you be able to use the plus sign in that regard?)
(1.) Provide any of these details if they are lacking in any DB post:
Well-written comments; another approach/method to solving the question; any additional relevant details; etc.
(2.) Review the post (Discuss Questions and Assess Questions) done by your colleagues.
If your colleague developed a console application for a program, develop a desktop application for the same program.
If your colleague developed a desktop application for a program, develop a console application for the same program.
(3.) Other substantive responses.
(1.) Textbook: Question (24.) on Pages 110 - 111
(2.) Review the example code of: Variables, Data Types, Values.
Line #25 displayed the value of the double data type as 40860.69
However, the output displayed the value as 40860.7
Explain the issue.
Write the program and fix the issue.
(3.) Develop a Graphical User Interface (GUI) of a short story, a poem, or drama using at least five sentences and
at least five different variables and data types.
At least three buttons: the button that displays the information, the Clear button and the
Exit button should be included.
(4.) Develop a Graphical User Interface of a short story, a poem, or drama using at least five sentences,
the same variable, and at least three different data types.
At least three buttons: the button that displays the information, the Clear button and the
Exit button should be included.
operator, operation, operand, operator precedence, number, byte, short, long, integer, float, double, decimal, standard input stream (cin), standard output stream (cout), insertion operator (<<), extraction operator (>>), operators, assignment operator, arithmetic operators, compound assignment operators, increment operator, decrement operator, relational and comparison operators, logical operators, conditional ternary operator, comma operator, bitwise operators, explicit type casting operator, sizeof operator, function, parameter, <cmath> library, <iomanip> rounding numbers, setprecision, printf, round, ceil, floor, trunc, nearbyint, rint
Students will:
(1.) Discuss the operators in C++
(2.) Perform operations on variables/values.
(3.) Write C++ programs involving the use of operators.
(1.) Textbook Chapter
(2.) Tutorials by cplusplus.com: Operators
and Basic Input/Output
(www.cplusplus.com/doc/tutorial/operators/)
(3.) Tutorials by w3schools: C++ Operators
and C++ Math
(www.w3schools.com/cpp/cpp_operators.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Numbers and/or C++ Operators in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Numbers and/or C++ Operators in the search bar and view/read the results.
Operators are special symbols that perform specific operations on one or more operands,
and returns an output.
An Operand is the variable/value on which an operation is done.
Operators | Symbols | Description | Code Examples |
---|---|---|---|
Assignment | $=$ | Equal sign |
int num1 = 7;
|
Arithmetic Addition Subtraction Multiplication Division Modulo |
$+$ $-$ $*$ $/$ $\%$ |
Add Subtract Multiply Divide Remainder after a division |
int num1 = 5, num2 = 2;
|
Comma |
$,$ |
The Comma operator is used to separate two or more included expressions where only one expression is expected. If the set of expresssions is to be evaluated for a value, only the right-most expression is considered. |
int num1, num2;
|
Conditional Ternary |
$?$ |
The Conditional ternary operator evaluates an expression amidst two results. If the expression is true, it returns the first result. If the expression is false, it returns the second result. The two results are separated by a colon : The expression is separated by the two results using the conditional tenary operator (question mark) ? The syntax is:
expression ? result1 : result2
|
int num1 = 5, num2 = 2;
|
Increment and Decrement Increment Prefix Increment Suffix Increment (Postfix Increment) Decrement Prefix Decrement Suffix Decrement (Postfix Decrement) |
$++$ $++p$ $p++$ $--$ $--p$ $p--$ |
Increase by one ($+=1$) Prefix Increment (evaluate the value, after it is increased) Suffix Increment (evaluate the value, before it is increased) Decrease by one ($-=1$) Prefix Decrement (evaluate the value, after it is decreased) Suffix Decrement (evaluate the value, before it is decreased) |
int num1 = 9;
|
Compound Assignment Plus equal (Add equal) Subtract equal Multiply equal Divide equal Modulo equal Right Shift equal Left Shift equal Bitwise AND equal Bitwise OR equal Bitwise XOR equal |
$+=$ $-=$ $*=$ $/=$ $\%=$ $\gt\gt=$ $\lt\lt=$ $\&=$ $|=$ ^$=$ |
Add, then equal to Subtract, then equal to Multiply, then equal to Divide, then equal to Remainder after division, then equal to Right Shift then equal Left Shift then equal Bitwise AND then equal Bitwise OR then equal Bitwise XOR then equal |
double num1 = 5;
|
Relational and Comparison Equal to Not equal to Greater than Less than Greater than or equal to Less than or equal to |
$==$ $!=$ $\gt$ $\lt$ $\ge$ $\le$ |
Relational and Comparison Operators are used to compare two expressions. The result is a Boolean (either $1$ for true or $0$ for false) |
int num1 = 5, num2 = 2;
|
Review the rest of the Operators
Let us review more examples of Arithmetic Operators and Math Functions.
A Simple Arithmetic Operation of Two Integers:
Teacher: Did you notice the quotient?
Student: Yes, Sir. I did.
That result is incorrect.
Teacher: Yes, it is.
Any suggestions?
Student: I think it is because it was declared as an integer.
Teacher: Correct.
How do we fix it?
Student: Declare it as a float?
Teacher: Let's see
Teacher: That fixed it.
But, what if we declared as a double type?
Student: That should work also, I guess?
Teacher: Let's see
Teacher: That fixed it as well.
However, which one is better: declaring as the float type or double type?
Student: Does it really matter?
Teacher: If the output is a repeating or non-terminating decimal, it does.
Student: In that case, I think the double type is better because it allows for more
decimal places.
Teacher: In other words, the double type has a greater precision than the float type.
Student: Yes, Sir.
Teacher: The god programming practice would be to declare the two operand variables: num1 and num2
as integers (because that is what they are) and to declare the output variables (result of each operation) as
double data types.
Because the double data type has a greater precision that the float data type, we
shall be using the double data type going forward.
Let us review more examples.
Please visit the Numbers website
(www.numbersandnotations.appspot.com/numbers.html)
Let us solve Question (10.) on that website using only Arithmetic Operators:
Student: That is pretty straightforward.
However, what about the green line under the operation?
Teacher: The green line is a warning.
It is not an error.
It is not an issue for now.
Point your mouse at it, review it and do some research on it. "Bing" it, or "Google" it
We can discuss it later.
Student: No, Mr. C
You said we should avoid all warnings and errors in our code.
I guess you just want to give me extra work to figure it out.
Teacher: No worries. Let us fix it.
What is the message displayed by the IDE?
Student: C26451 Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte
value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2)
Teacher: Casting to an 8-byte value is to use the long data type.
Let us declare it with the long data type.
Here is the fixed code:
Student: When do we know whether to declare it as long or as double?
Teacher: When you receive such warning.
Student: Is there any way we can declare it as double without having that warning?
I've just got used to double.
Teacher: Yes.
Let us use C++ Math functions: the <cmath> library
We shall use the double data type and the Math functions and the code should work fine without any warning.
Let us solve Question (10.) on that website using Arithmetic Operators and Math Functions:
Student: Pretty cool.
Teacher: Yes, we used the C++ Math functions in this example.
Hence, we included the <cmath> library.
There are more C++ math functions.
Please see the Complete list of C++ Math Functions
(https://www.cplusplus.com/reference/cmath/)
Let us review a case where the answer needs to be rounded.
There are several ways of rounding numbers in C++
They include:
(1.) Using the setprecision function.
(https://www.cplusplus.com/reference/iomanip/setprecision/)
This function sets the decimal precision to be used to format floating-point values on output operations.
It accepts one parameter: the new value for the decimal precision.
The value for the parameter is "kinda" tricky.
Say:
the result is 3.157; to round to one decimal place, set the value of the parameter to 2 (setprecision(2)
)
the result is 3.157; to round to two decimal places, set the value of the parameter to 3 (setprecision(3)
)
the result is 37.157; to round to one decimal place, set the value of the parameter to 3 (setprecision(3)
)
the result is 37.157; to round to two decimal places, set the value of the parameter to 4 (setprecision(4)
)
In other words, the value of the parameter should include the number (count) of the digits before the decimal place and the
number of decimal places that the decimal should be rounded to.
To use this function, the Input/Output Manipulators: <iomanip> library must be included in the header.
(2.) Using the Print Formatted:function: printf
(https://www.cplusplus.com/reference/cstdio/printf/)
This function prints formatted data to the standard output (stdout).
To use this function, there is no need to include the <cmath> or <iomanip> library.
Typically, it follows this format: %[flags][width][.precision][length]specifier
The precision is the number of places to round the number (the number of decimal places after the decimal).
Did you notice that the meaning of precision using printf is different from the meaning of
precision using setprecision?
It has the same functionality as the standard output stream, cout in that it displays the output, but a formatted output.
This implies that: in the same line of code, we do not use the cout command when we use the printf function.
Keep in mind that the cout command can also display formatted output.
(3.) Using other <cmath> library rounding functions.
These include:
(a.) The Floor function: floor
: Round Down
It rounds the number downward, returning the largest integral value that is not greater than the number.
(Compare to the floor of a room).
(b.) The Ceil function: ceil
: Round Up
It rounds the number upward, returning the smallest integral value that is not less than number.
(Compare to the ceiling of a room).
(c.) The Round function: round
: Round Nearest
It returns the integral value that is nearest to number, with halfway cases rounded away from zero.
(d.) The Truncate function: trunc
: Truncate value
It rounds the number toward zero, returning the nearest integral value that is not larger in magnitude than the number.
Let us demonstrate some of these appraoches to rounding numbers.
Please visit the
Percent Applications website
(www.fractions-decimals-percents.appspot.com/percentApplications.html)
Let us solve Question (1.) on that website
In this example, let us use several variables to solve the question.
We can solve the same question using only one variable.
In this case, we have to use Compound Assignment Operators
Let us solve Question (1.) on that website using Compound Assignment Operators:
Student: Mr. C
Did you use the <cmath> library in those two examples?
Teacher: I did not.
Student: So, why include it?
Teacher: Good question.
You must not include it because we did not use it.
But, this is a general advice:
Anytime you are writing C++ code to solve a Math problem, it is better to include it should you use a Math function
But, in those two examples; it is proper not to include it.
Student: How did you underline the words in the Console window?
The codes you used...
Teacher: Yes, the codes underline words in the Console window
They work for C++ and C# console window applications
You can also add foreground and background colors.
This is the List of the Console Log Formatting Commands
(https://www.samdomforpeace.com/References/ASCII.html#console)
\x1B[4m command underlines the text in the console.
\x1B[0m command resets it (closes the underlined text).
It is important to reset it, else it will underline the entire text in the console.
If you add foreground and background colors, it is also important to reset.
One of the nice features of the C++ langauge is the input/output feature.
This feature is interactive.
You use this input/output feature in several applications.
A common application is whereby you are required to verify your identity by inputting your first
name, last name, date of birth, etc.
Let us demonstrate the input/output feature with numbers so we see how it works.
Notice that: we use the standard output stream: : cout and the extraction operator: << to request the user input
and we use the standard input stream: : cin and the insertion operator: : >> to store the user input.
C++ Input/Output Feature for Arithmetic Operations and Math Functions
We can solve this question using a better efficient approach: using the getline function and the stringstream type.
The stringstream feature is useful for converting strings to numerical values and vice versa.
It is accessed by including the header library, <<sstream>>
We shall include the <<string>> library as well.
Let use this feature to solve the same question.
Student: May you please let me know how this approach is better than the first approach?
Teacher: Using this approach, the numeric values are acquired from the standard input indirectly.
Instead of extracting numeric values directly from cin (using the first approach), we get lines from it into a
string object (userString), and then we extract the values from this string into the variables:
firstNum, secondNum, thirdNum.
Using this approach of getting entire lines and extracting their contents, we separate the
process of getting user input from its interpretation as data.
This allows for the input process to be what the user expects, and at the same time gain more control over the
transformation of its content into useful data by the program.
Please review the BMI information on these two government websites [from the Center for Disease Control and Prevention (CDC) and the National Heart, Lung, and Blood Institute of the National Institutes of Health (NIH)]
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC and
Calculate Your BMI - Standard BMI Calculator
As at today, the 3rd day of September, 2020; the BMI information on both websites are:
NIH website
Calculate Your BMI - Standard BMI Calculator
CDC website
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC
$ BMI = \left(\dfrac{weight}{height * height}\right) * 703 \\[5ex] weight\:\:is\:\:in\:\:pounds (lb) \\[3ex] height\:\:is\:\:in\:\:inches (in) $
$ BMI = \left(\dfrac{weight}{height * height}\right) \\[5ex] weight\:\:is\:\:in\:\:kilograms (kg) \\[3ex] height\:\:is\:\:in\:\:meters (m) \\[3ex] $ If you need help with conversion of units, please review the Tables and Examples in Measurements and Units
Teacher: What do you notice in both websites?
Student: They both have the information on the BMI.
In addition, the CDC website has information for both Adult BMI and Child & Teen BMI among others.
The NIH website has recommendations among others.
Teacher: That is correct. What else?
Student: They have the BMI calculator.
Teacher: Did you notice any difference in the calculator on both websites?
Student: The NIH website has BMI calculator for both Standard and Metric versions.
The CDC website has the BMI calculator for only the Metric version.
Teacher: Did you notice any issue/concern about the BMI information?
Student: Not really. Why?
Teacher: So, this is what we are going to do.
Let us develop the BMI calculator.
That calculator will calculate the BMI.
Then, we shall interpret that BMI, and make a recommendation.
.
The CDC website gave us the formula for calculating the BMI. So, we shall use it.
As you can see, our calculator would have to use conditional statements for the interpretation and recommendation.
But, here is the issue.
Student: Wait, I think I see the issue.
The issue is with the domains.
Teacher: Correct!
Anyone having a BMI between $18.5$ and $24.9$ both endpoints included has a Normal weight.
This is: Normal weight: [18.5, 24.9]. It is a closed interval (relate with Mathematics).
So, the Overweight range for the BMI should be the weight greater than $24.9$, (rather than beginning from $25$) and ending at $29.9$
For the Overweight range, the first endpoint is not included, but the second endpoint is included.
This is: Overweight: (24.9, 29.9]. It is a half-open half-closed interval (relate with Mathematics)
Teacher: Do you know why this would be a problem if the programmer does not fix these issues before developing the calculator?
Student: Yes. Because there would not be any interpretation for anyone whose BMI is between $24.9$ and $25$
But, I do see that the BMI information is for values rounded to one decimal place.
Teacher: That is correct.
And we shall develop our calculator to round to one decimal place.
But, it is important we fix the issues.
What if we do not want to round?
Look at the two examples on the CDC website. The BMI values were rounded to two decimal places.
If we developed our calculator to round to two decimal places with the information on those websites "as is"; then we would not have the interpretation and recommendation for those two examples ($24.98$ and $24.96$) because those values are greater than $24.9$ but less than $25$.
Student: That makes sense.
So, the last one: Obese should be BMI greater than $29.9$, rather than greater than $30$?
Teacher: That is correct.
Let us apply what we learned so far.
We shall develop a console application and a desktop application for the Body Mass Index (BMI) calculator.
I do the console application.
You do the desktop application.
We are yet to cover Statements (covered in Module 5). However, do not worry.
I explained my comments very well. You will understand the comments.
Please ask questions if you do not understand any of the comments.
We shall use part of Module 5 (Decision-making statements) in the program.
Please review the screenshots and the comments.
(1.) The program should accept user inputs of:
(I.) First name
(II.) Last name
(III.) Weight
(IV. Height
(2.) The program should output the:
(A.) BMI value
(B.) Interpretation
(C.) Recommendation
(3.) The program should address user-input errors of non-positive numbers for the weight and the height.
Inform the user.
Then, exit the program. Do not allow the program to continue.
To exit the program, we use the command: exit(0);
Logical AND in C++ is represented by the double ampersand symbol &&
Logical OR in C++ is represented by the double pipe symbol ||
Student: I have several questions, Mr. C
Teacher: Please go ahead
Student: First Question: Why did you initialize those variables?
The interpretBMI and the adviceBMI...you initialized them to empty strings
Teacher: Good question.
Assume we did not initialize them
We only defined them within the block of code: the If Statement
Then, we want to print them/output them outside the block of code
The program "will not be happy"
Compare it to this scenario.
A student registered to attend a school.
We did not register the student at the front office registration desk.
But we sent the student to a classroom and the classroom teacher registered that student.
The parents come, looking for their child.
Where will the parent go first?
Student: At the front desk of course
Teacher: Good.
The front desk will first keep a record of the student before sending the student to the class.
We have to first assign the string to something before we send it to the blocks of code, and then output it.
We cannot just declare it without an assignment, then send it to a block of code to be used within that block of
code only, and then want to output it outside the block of code.
Does it make sense?
Student: Yes, it does.
But what if we do not want to print the value outside the block of code?
What if we want to print the value inside each block of code where it is used?
Teacher: I am impressed by your questions.
Yes, we can do that.
But you know what that means...right?
Student: We have to write it each time for each of the conditional statement.
Teacher: That is correct.
Student: Second Question: Why did you underline the 0 on the console window?
....process exited with 0?
Teacher: Unless defined in the program otherwise; anytime you run a program and the program exited with 0,
it means that the program successfully exited.
0 basically lets you know that the program ended successfully.
For Questions (1.) and (2.); please review the other C++ operators
Using code examples and well-written comments for each operator, discuss any of these operators.
(1.) Logical Operators
(2.) Bitwise Operators
(3.) Visit the Numbers website
(www.numbersandnotations.appspot.com/numbers.html)
Choose any applicable question and write a C++ program to solve it.
Please make sure that the output of your program gives the same result as the solution of the
question on my website.
You may use Arithmetic Operators, Math Functions, or both.
(4.) Visit the Percent Applications website
(www.fractions-decimals-percents.appspot.com/percentApplications.html)
Choose any applicable question and write a C++ program to solve it.
Please make sure that the output of your program gives the same result as the solution of the
question on my website.
You may use Arithmetic Operators, Math Functions, or both.
For Questions (4.) and (5.), please see the code (image) below:
Arithmetic Operators; Increment and Decrement Operators:
(5.) There is no problem with the code as indicated by the bottom right message "No Issues found".
However, the user is confused with the output.
Explain to the user, the code and the output.
Try to clear any confusion the user have. What changes will you make?
Are there any questions you would ask the user? What are those questions?
Assume different answers the user may give, and provide suggestions.
(6.) The user wants to apply the incremental operator to num1 and the decremental
operator to num2 before applying the arithmetic operators.
How would you fix it? Fix it.
Keep in mind that the user wants a well-written output.
(7.) Please see the code (image) below:
C++ Input/Output Feature for Arithmetic Operations and Math Functions.
How would you check for the user error, a12.e8 in your program?
What are your suggestions?
(8.) Can you declare the float or double type variables for the modulo operation?
Give reasons for your answer. Use code examples and submit screenshots the code and the outputs.
(9.) Please review the Precedence of operators
(https://www.cplusplus.com/doc/tutorial/operators/)
Using code examples, demonstrate all the operators and the operations are executed using the precedence of operators.
(10.) Program to determine your age
***Because your age is a PII (Personal Identifiable Information), you may use a fictitious age.
However, you need to test it (privately) with your actual age to make sure it works.***
Develop a C++ program to determine your age based on these instructions.
ONLY one variable is required.
(Hint: If only one variable is required, this implies that you need to use Compound
Assignment operators)
The user wants you to note that these instructions would only work for ages determined this year, and wants you
to specify it in the program.
(a.) Pick an integer between 0 and 10 (0 and 10 exclusive).
(b.) Multiply the integer by two.
(c.) Add five to the result.
(d.) Multiply the result by fifty.
(e.) If you already had your birthday this year, add the result to one thousand, seven hundred
and seventy-two.
If you have not had your birthday this year, add the result to one thousand, seven hundred
and seventy-one. (valid for 2022, adjust accordingly after 2022)
(f.) Subtract your four-digit birth year from the result.
Run the code and display the output.
Explain your result.
(11.) A client wants you to develop a program to calculate the age of his child.
The instructions for the previous question still applies to this question.
However, in this case; the program will give the instructions to the child, and the child will
respond.
This program is an Input/Output program.
This implies that the cout (standard output stream) and cin (standard input stream) will be
used.
Develop a C++ program for this child.
(12.) Program to determine your date of birth.
***Because your date of birth is a PII (Personal Identifiable Information), you may use a
fictitious age. However, you need to test it (privately) with your actual age to make sure it
works.
Develop a C++ program to determine your date of birth based on these instructions.***
ONLY one variable is required.
(Hint: If only one variable is required, this implies that you need to use Compound
Assignment operators).
(a.) Pick the integer that is your month of birth.
(b.) Multiply the integer by two hundred.
(c.) Add three hundred and eighty two to the result.
(d.) Divide the result by two.
(e.) Add your day of birth to the result.
(f.) Multiply the result by 100.
(g.) Add thirteen thousand, eight hundred and forty to the result.
(h.) Add the last two digits of your year of birth to the result.
(i.) Subtract thirty two thousand, nine hundred and forty from the result.
Run the code and display the output.
Explain your result.
(13.) A client wants you to develop a program to calculate the date of birth of her child.
The instructions for the previous question still applies to this question.
However, in this case; the program will give the instructions to the child, and the child will
respond.
This program is an Input/Output program.
This implies that the cout (standard output stream) and cin (standard input stream) will be
used.
Develop a C++ program for this child.
C++ Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C++ Basic: Exercises, Practice, Solution
(B.) C++ Basic Algorithm: Exercises, Practice, Solution
(C.) C++ Math: Exercises, Practice, Solution
(D.) C++ Numbers: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(14.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write clear comments for each line of code in the Solution.
Run the program.
Submit clear screenshots.
Textbook Questions
(15.) Question (12.) on Page 118
(16.) Question (24.) on Page 121
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for C++
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for c++ programmer, you might be surprised that even for entry level positions
for a C++ Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with C++
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in C++ and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in C++ and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C# Basic Declarations and Expressions : Exercises, Practice, Solution
(B.) C# Basic Algorithm: Exercises, Practice, Solution
(C.) C# Data Types : Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(17.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your porgram output is the same solution
Submit clear screenshots.
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) Java Math: Exercises, Practice, Solution
(B.) Java Basic Programming - Part 1: Exercises, Practice, Solution
(C.) Java Basic Programming - Part 2: Exercises, Practice, Solution
(D.) Java Data Types: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(18.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your porgram output is the same solution
Submit clear screenshots.
(1.) Provide any of these if it is lacking in any DB post that solved any question in the
Assess tab of this module: Well-written comments; another approach/method to solving the
question; any additional relevant details; etc.
For Questions (10.) and (11.) in the Substantive Posts
Student: Mr. C, the instructions in Questions (10.) and (11.) are wrong.
The result is not my age.
How can you ask us to write a program that does not work?
(2.) Explain the result to the Student. (Answer this question only if any of your colleagues made a similar statement in the initial post.)
(3.) The Student wants only his/her age to be the result.
Without modifying any of the instructions (but using all of them) and one more instruction, extend the
program to display only the Student's age.
What is the extra instruction that you would include to work for all ages?
Write it. Run it. Submit clear screenshot.
For Questions (12.) and (13.) in the Substantive Posts
Student: Mr. C, I want the date of birth to display properly.
Teacher: Use a delimiter.
Student: What is a delimiter?
Teacher: A delimiter is a sequence of chararcters that specifies limits/boundaries of characters
in a text, expression, word, etc.
A good example is the forward slash that you can use to separate that DOB in the form of: mm/dd/yyyy.
The forward slash is a delimiter.
Another example is the pipe delimiter: mm | dd | yyyy.
Another example is the hyphen delimiter: mm-dd-yyyy.
Student: Okay, how do I display the result in that format?
(4.) Explain how you would display the result for the Student.
Write the code. Run it. Submit clear screenshot.
(5.) If your colleague developed a console application for a program, develop a desktop application for the same program.
If your colleague developed a desktop application for a program, develop a console application for the same program.
(6.) Other substantive responses.
(1.) Develop a console application for an extension of the Body Mass Index (BMI) application example.
We did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Based on the user's selection, display the appropriate output.
Test all the conditions for both systems.
Textbook Questions
(2.) Question (8.) on Page 117
(3.) Question (16.) on Page 119
(4.) Question (18.) on Pages 119 and 120
(5.) Question (20.) on Page 120
character, string, Boolean, bool, function, argument, dot member access operator, concatenator operator, string literal, empty string
Students will:
(1.) Discuss the C++ String data type
(2.) Discuss the C++ Boolean data type
(3.) Discuss date and time functions in C++
(4.) Write programs that involves the String data type.
(5.) Write programs that involves the Boolean data type.
(6.) Write programs that involves Date and Time.
(1.) Textbook Chapter
(2.) Boolean Operators
(https://www.cplusplus.com/doc/boolean/)
(3.) C++ Strings
and C++ Booleans
(https://www.w3schools.com/cpp/cpp_strings.asp) and (https://www.w3schools.com/cpp/cpp_booleans.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Strings and/or C++ Booleans and/or C++ Date and Time in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Strings and/or C++ Booleans and/or C++ Date and Time in the search bar and view/read the results.
A string is a variable in C++ that contains a collection of characters enclosed in
double quotation marks.
It must be enclosed in double (not single) quotation marks.
Remember the first C++ program we wrote, the output...the message, THANK GOD.
That is an example of a string.
Let us review more examples of what we could do with C++ strings.
Join two strings using Insertion operator and Concatenation operator - Example 1
Teacher: There is an issue here.
Student: There is no space between your first and last name.
Teacher: That is correct.
How do we fix it?
Student: Include a space between the names.
Teacher: There are several ways we can do this.
We can include an empty string space in between the names.
Join two strings using Insertion operator and Concatenation operator (Space included between the
strings) - Example 2
Teacher: We can also use the Append function.
The Append function does not automatically include a space between the strings.
So, we have to include the space in the assignment of either string variable.
Join two strings using Insertion operator and Concatenation operator (using the Append
function) - Example 3
Student: We could have also inserted a space after the first name in the previous
example.
That way, there would be no need for the empty double quotes and the empty space of the
additional insertion operator.
It is more efficent than inserting those empty spaces.
Teacher: That is correct.
Choose whatever way you prefer.
Let us review another function: The Insert function.
The Insert function inserts additional characters into the string right before the
insertion point.
Let us write my full name: Samuel Dominic Chukwuemeka (first name, middle name, last name)
Say we want to insert my middle name in between my first name and my last name.
This implies that we are going to insert Dominic between Samuel Chukwuemeka
The l in Samuel is in the 6th position
The space between the l in Samuel and the C in Chukwuemeka is in the 7th position
Let us review the code to implement the Insert function.
Insert a string (using the Insert function) - Example 4
Sometimes, we write sentences that has single quotation marks and the double quotation marks.
How do we display these sentences in a C++ program?
We have to use the backslash escape sequence
It turns special characters into string characters.
Insert single quote, double quote, backslash in sentences
In the previous module, we reviewed some examples of the Input/Output with Numbers.
In this module, let us demonstrate the Input/Output feature with strings.
In this case, we must include the <<string>> library.
C++ Input/Output Feature for String Variables - Example 1
Look at another example.
C++ Input/Output Feature for String Variables - Example 2
Teacher: Did you notice the issue?
Student: Yes, Sir
Teacher: How do we solve it?
Student: I do not know.
Teacher: We can fix it by using the getline function.
Let us fix it.
The issue with Example 2: The cin (extraction operator) considers spaces including
whitespaces and tabs
as terminating the value being extracted.
This implies that it extracts a string as a single word, not as a phrase or a sentence.
This is because it terminates once it sees a space.
The solution to Example 2: To get an entire line from cin, we need to use the
getline function,
that takes cin as the first argument, and the string variable as the second argument.
Let us see the solution.
C++ Input/Output Feature for String Variables - Example 2 Correction
Teacher: What are you looking at?
You already know.
Student tries to hide it.
Teacher: I want to ask you something.
Look at it.
Please turn it off...remember the course syllabus.
Before you turn it off, do you see two numbers in the Power off button?
Student: Numbers?
I do not see numbers.
It's an icon.
Teacher: Yes, they are numbers.
The numbers are: 0 and 1
1 is inside the 0 in most devices.
Student: Interesting.
Teacher: 0 represents OFF
1 represents ON
You see these two numbers in almost all electronic devices (tablets, smartphones, computers) including some
electric switches.
In Logic, 0 represents FALSE
1 represents TRUE
We use true and false Boolean values in Statements including conditional statements and
iterative statements.
We shall cover Statements in the next module.
The use of these two numbers: 0 and 1 in Mathematics and Computer Science to repesent FALSE and
TRUE values is known as Boolean Algebra
It was developed by George Boole, an English mathematician/philospher/logician.
We can also use these Boolean numbers 0 and 1 to represent choices/options of NO and YES
A Boolean is a fundamental data type in C++ that:
(1.) is declared with the keyword, bool
(2.) can represent only one of two states: true or false
(3.) gives an output of only one of two values: 1 or 0
1 represents true
0 represents false
(4.) is used for comparison (in relational and comparison operators) to compare expressions.
(5.) is used in statements (conditional statements and iterative statements) to make decisions.
A Boolean Expression is an expression that returns a Boolean value.
Let us demonstrate some examples of the use of Booleans
#define _CRT_SECURE_NO_WARNINGSWe have several approaches to returning date (day, month, year) and time.
You may use strings not written in English language. However, if you use any language other than English language,
please make sure you translate it. Your colleagues and I need to understand any language you use.
Insensitive words or any word deemed inappropriate to any race, gender, religion, and national origin among others are
unacceptable. Any violation will not yield any point.
If you are not sure of the words/string to use, please contact me first.
Please review all the member functions of strings here:
https://www.cplusplus.com/reference/string/string/
Scroll down until you see member functions:
As at the time of this writing;
The first one/link on the list is the string::append (the Append function)
The last one/link on the list if the string::swap (the Swap function)
Click on each link and review the example/how it is used.
(1.) Pick any five methods besides the ones I discussed.
Write the code examples for each of the five methods and implement each of them.
Run your codes.
Display the results.
Submit clear screenshots of your code examples of each of the five methods and the corresponding results.
You may use strings not written in English language. However, if you use any language other than English language, it is
important you translate it. Your colleagues and I need to understand your code.
Insensitive words, or any words deemed inappropriate to any race, gender, religion are unacceptable. Any violation will
not yield any point.
If you are not sure of the words/string to use, please contact me first.
(2.) Please review the Date and Time example in this module.
Our students come from the entire 50 states of the United States and its territories.
However, the United States has different time zones.
Find out/browse/learn/discover the different time zones in the United States and its territories as seen in the
The Official U.S. Time (https://time.gov/) according to the
National Institute of Standards and Technology
Include those time zones in your comments.
Display the current date and time for each time zone.
Verify your answer with the times and time zones on that website.
(3.) C++ Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C++ Strings: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write clear comments for each line of code in the Solution.
Run the program.
Submit clear screenshots.
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for C++
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for c++ programmer, you might be surprised that even for entry level positions
for a C++ Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with C++
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in C++ and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in C++ and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C# Strings : Exercises, Practice, Solution
(B.) C# Date and Time: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(4.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) Java Strings: Exercises, Practice, Solution
(B.) Java Date and Time: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(5.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
(1.) Review the post of your colleague.
Use at least one different string function to work on the same string used by your colleague.
(2.) Provide any of these if it is lacking in any DB post that solved any question in the
Assess tab of this module: Well-written comments; another approach/method to solving the
question; any additional relevant details; etc.
(3.) If your colleague developed a console application for a program, develop a desktop application for the same program.
If your colleague developed a desktop application for a program, develop a console application for the same program.
(4.) Other substantive responses.
You may use strings not written in English language. However, if you use any language other than English language,
please make sure you translate it. Your colleagues and I need to understand any language you use.
Insensitive words or any word deemed inappropriate to any race, gender, religion, and national origin among others are
unacceptable. Any violation will not yield any point.
If you are not sure of the words/string to use, please contact me first.
(1.) We are yet to do Statements (in the next Module), but you can give this question a try.
A string palindrome is a word, phrase, clause or sequence of characters that is
spelled and read the same way backward and forward.
In other words, when one reads it as is, reverses it and reads it again; the pronunciation is the same.
Examples include the:
Words: HANNAH, BOB, madam, level, civic, racecar, rotor
Phrase: never odd or even
Clause: nurses run
Sentence: Was it a car or a cat I saw?
Write a C++ program that asks for user input.
Determine if the user input is a string.
If the user input is not a string, ask the user to enter only a string.
If the user input is a string, determine if it is a string palindrome.
Inform the user whether it a string palindrome or not.
Test at least one example of: Words, Phrase, Clause, and Sentence that was listed.
This implies testing at least four examples.
Submit clear screenshots of the code and the results.
(2.) Please review the Date and Time example in this module.
Our students come from the entire 50 states of the United States and its territories.
However, the United States has different time zones.
Find out/browse/learn/discover the different time zones in the United States and its territories as seen in the
The Official U.S. Time (https://time.gov/) according to the
National Institute of Standards and Technology
Include those time zones in your comments.
Display the current date and time for each time zone.
Greet each user (your fellow colleague) according to their time zones (their own current times).
If the time is between 12:00:01 AM to 12:00:00 PM (inclusive), greet Good Morning.
If the time is between 12:00:01 PM to 04:00:00 PM (inclusive), greet Good Afternoon.
If the time is between 04:00:01 PM to 12:00:00 PM (inclusive), greet Good Evening.
You may use 12-hour or 24-hour time formats.
These are the minimum requirements. You are welcome to add more functionalities.
(3.) Write a C++ program that solves Question (8.) on the
Applications of Numbers website.
(https://numbersandnotations.appspot.com/numbersApplications.html)
Use any actual date that is a Tuesday.
Ensure that the output of your program corresponds to the solution on the website.
Please display: the actual date, the actual day, the new date and the new day in your output.
In other words, I am looking for the input date that corresponds to a Tuesday, the input day that is the Tuesday,
the output date that corresponds to a Friday, and the output day that is the Friday.
Please check to ensure your program gives the correct output (result).
You may develop a console application or a desktop application for this program.
Submit screenshots of the question, your program, and the output of your program.
statement, program, linear sequence, flow control, flow of execution, statement block, nested blocks, declaration statements, expression, expression statements, control flow statements, conditional statements, selection statements, decision-making statements, decisions, branches, repetitive statements, iteration statements, loops, for loop, while loop, do-while loop, jump statements
Students will:
(1.) Discuss Statements in C++
(2.) Write conditional statements.
(3.) Write iterative statements.
(4.) Write programs that solve real world problems using statements.
(5.) Complete the Midterm Project on Piecewise Functions.
(1.) Textbook Chapter
(2.) Statements
(www.cplusplus.com/doc/tutorial/control/)
(3.) C++ Conditions to C++ Break/Continue
(www.w3schools.com/cpp/cpp_conditions.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Statements and/or C++ Conditional Statements in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Statements and/or C++ Conditional Statements in the search bar and view/read the results.
A statement in C++ is an individual instruction of a program.
It ends with a semicolon.
Statements are executed in the same order in which they appear in the program.
C++ statements can consist of:
(1.) Linear sequence of statements.
These are the statements we have been writing in previous modules.
These statements flow in a linear order...line by line as they were written.
(2.) Conditional statements or Selection statements or Branches.
These statements are executed based on decisions.
Examples are: If statements, If-else statements, If-else if-else
statements, Multiple Ifs statements
(3.) Repetitive statements or Iteration statements or Loops.
These statements are repeated and executed a certain number of times until a condition is met.
Examples are: for loops, while loops, do-while loops
All the codes we have written so far are mainly linear statements.
In this module, we shall write conditional statements and repetitive statements.
if (condition) { statement; }C++ ignores whitespaces so you can also write it this way:
if (condition) { statement; }
if (condition 1) { statement; } else { statement; }C++ ignores whitespaces so you can also write it this way:
if (condition) { statement; } else { statement; }We can also write simple If-else statement using the Ternary operator
variable = if (condition) ? statement if true : statement if false;
(3.) If-else if - else statement if (condition 1) { statement; } else if (condition 2) { statement; } else if (condition 3) { statement; } else { statement; }Whitespaces are ignored in C++. Therefore you can also write it this way:
if (condition 1) { statement; } else if (condition 2) { statement; } else if (condition 3) { statement; } else {statement; }Keep in mind that we do not specify condition 4 in the code for the else statement because we already know that statement for the else statement would only be executed if all the other prior conditions are not met.
if (condition 1) { statement; } if (condition 2) { statement; } if (condition 3) { statement; } if (condition 4) { statement; }Whitespaces are ignored in C++. Therefore you can also write it this way:
if (condition 1) { statement; } if (condition 2) { statement; } if (condition 3) { statement; } if (condition 4) { statement; }Review the Definitions of Numbers
%i
i
stands for an integer data type printf
int variable switch (variable) { case 1: statement; break; case 2: statement; break; case 3: statement; break; default: statement; }NOTE In C++, the variable in the switch keyword must be an integer data type or the enumeration (enum) type.
dataType variable; if condition 1 { If condition 2 { statement; } else { statement; } } else if condition 3 { if condition 4 { statement; } else { statement; } } else { statement; }Notice the order in which each nested conditional statement is closed.
for (initialize; condition; increment/decrement) { statement; }While Loop
initialize; while (condition) { statement; increment/decrement; }Do-While Loop
initialize; do { statement; increment/decrement; } while (condition);Example 1: Print the first ten positive integers using the three types of loops
firstNum++
and thirdNum++
(as we did in the for loop and do-while loop)
or the post fix increment operator: ++secondNum++
(as we did in the while loop)
Jump statements are statements that control the flow of a program by performing jumps
to specific locations.
They include:
(1.) The Break statement
(2.) The Continue statement
(3.) The Goto statement
Jump statements are not standalone statements.
They are usually embedded in/used with selection statements and iteration statements.
Break Statement
The break statement breaks/stops a loop even when the loop is still running.
In other words, even if the conditions for a loop has not been satisfied, introducing the break statement
at any point in the loop stops the loop and ends the program.
A good advantage of the break statement is that it can be used to end an infinite loop.
Continue Statement
The continue statement causes the program to skip a portion of the loop, and continue
the loop.
In other words, using the continue statement does not run the entire loop. It skips some part of the
loop and then allows the loop to continue.
Goto Statement
The goto statement causes the program to jump from one point in the program to another point
in the program.
This statement is rarely used.
Let us demonstrate these jump statements.
Please review all the screenshots and all the comments.
Jump Statements: Break Statement, Continue Statement, Goto Statement
Let us redo one of the examples we did using Iteration statements.
Let us redo the Example (2.) in Iteration statements, with Iteration and Jump statements.
Redo Example 2 in Iteration Statement using Iteration statement and Jump statement
Let us solve Question (34.) on Arithmetic Sequences
(www.samuelchukwuemeka.com/Sequences/arithmeticSequences.html) using
selection statements, iteration statements, and jump statements.
We shall use iteration statements: for loop, while loop, and do-while loop to solve the question.
Then, we shall use iteration statements, jump statements and selection statements to solve the question.
Application of Statements: Calculate the sum of the $n$ terms of an arithmetic sequence.
Iteration Statements, Selection Statements and Jump Statements
Student: Mr. C, I understand the initialization of the number of terms...as given by the syntax for the loops.
But, why did we initialize the sum to 0?
Teacher: We initialized the sum to 0 because we have to increment each number and add.
$1 + 2 + 3 + 4 + ...$ is the same as saying $0 + 1 + 2 + 3 + 4 + ...$
Student: Why did we initialize?
Why can't we just declare the variable and keep adding the numbers?
Teacher: We have to use "something" to hold the sum.
Because we need to keep adding to "something", we need to initialize "that thing".
"That thing" is the "sum"
Student: The solution on your website used a formula to solve that question.
If we were using formula to solve it, do we need to initialize the sum?
Teacher: Good question.
We do not.
However, some compilers are picky and would insist that you do.
It is a good practice to initialize variables.
Student: Do we always have to intialize to $0$?
Teacher: We do not.
If we were going to multiply (rather than add) numbers...say we declare product as the variable rather than sum, then we have to initialize that variable to $1$ because we shall be multiplying numbers to it rather than adding numbers to it.
The number you use to initialize a variable is to just hold a value to that variable...more like a placeholder.
It does not determine or influence the final result of that variable.
The midterm project is designed to assess your knowledge of Statements in solving real-world problems.
It is a Piecewise Function application.
Any other application will not considered.
Please:
(1.) Visit my website on: Piecewise Functions
(2.) Read the Story to understand the idea of Piecewise functions.
(3.) Read the Overview of Piecewise Functions for more understanding of Piecewise functions.
(4.) Study the Applications of Piecewise Functions
(5.) Review the Project Examples. Ensure you follow all the instructions and directions.
(6.) Review the Midterm Project rubric for your course.
(7.) Complete the Midterm Project for your course.
(8.) Ask questions. I can help.
If you have any issue at any time and you have reviewed the resources I provided and you cannot fix the issue,
please attend the Office Hours/Live Sessions so I can help you.
(9.) Include all these: (documentation of all your Math work and the .exe file) in OneDrive, create a
shareable link, and post the link in the Midterm Project Drafts forum of the course on Blackboard or send to me via email.
You may also upload them directly if you prefer.
I shall review and provide feedback.
(10.) When you are done with your project:
Make sure your executable file runs by itself outside the project folder
If it does run, include these three items: single executable file (that runs by itself outside the folder), the
Math documentation (Word document that has the Math part), and the entire project folder, into a folder,
zip the folder (.zip extension only) and submit it in the appropriate area of the Blackboard course.
If it does not run, please fix it.
If you cannot fix it, please attend the Office Hours/Live Sessions so I can help you.
NOTE: Any actual project submitted to me via email will not be graded.
If you wish to save some time for research:
Please review the Piecewise Function projects done by my previous students.
The direct link of the verifiable websites are included.
(I.) VB Projects
(II.) C# Projects
(III.) C++ Projects
(IV.) Java Projects
You may not do any same application done by any of my previous students for C++
You may do any Piecewise Function application not done by any of my previous students for C++
If you are not sure what project you may or may not do, please contact me via the school email.
function, method, pre-defined function, user-defined function, parameter, argument, function overload,
Students will:
(1.) Discuss functions.
(2.) Write functions that solves real world problems.
(3.) Overload functions.
(4.) Discuss function templates.
(1.) Textbook Chapter
(2.) Functions
to Name visibility
(www.cplusplus.com/doc/tutorial/functions/)
(3.) C++ Functions
to C++ Function Overloading
(www.w3schools.com/cpp/cpp_functions.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Functions in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Functions in the search bar and view/read the results.
int sumNumbers (int num1, int num2) { return num1 + num2; } sumNumbers (5, 7) // The result will be 12In that example:
return-data-type function-name ( data-type1 parameter1, data-type2 parameter2, ...) {
statements;
}
(1.) Using Example 6, include a condition that asks the user if the quadratic trinomial
is in general form.
If the user says no, ask the user to arrange the quadratic trinomial in general form before
prceeding. Then, quit the program.
If the user says yes, then proceed to run the program.
Arithmetic: Questions (2.) through (5.)
Please review the Definitions of Numbers on Numbers website:
Numbers and Notations
(https://numbersandnotations.appspot.com/#definitions)
Please make sure you indicate the type of number in your comments.
(2.) Write a function that prints any of those types of numbers between one and thirty ($1$ and $30$ are included)
(3.) Write a function that prints the first thirty numbers of any of those types of numbers.
Focus on the first positive thirty numbers of those kind of numbers.
(4.) Write a function that asks the user to input two values (those values could be
positive, zero or negative)
The function should print all the numbers for any of those types of numbers between those two
values.
Those two values should be included if they are part of those type of numbers.
(5.) Write a function that asks the user to put in a value (that value could be positive, zero,
or negative)
The function should print thirty values of those types of numbers up to and including the
user-input value.
Geometry: Questions (6.) and (7.)
Please review the Mensuration Formulas on Mensuration website:
Mensuration
(https://www.samuelchukwuemeka.com/Mensuration/mensuration.html)
Please make sure you indicate the type of figure/shape in your comments.
(6.) Write a function that asks the user to input the required parameters for any
two-dimensional figure.
The function should return the area and perimeter of that figure.
(7.) Write a function that asks the user to input the required parameters for any three-dimensional figure.
The function should return the surface area and volume of that figure.
Strings/Quotes: Questions (8.) and (9.)
Find a quote from any of your favorite authors or your favorite quote.
If you do not have any favorite author or a favorite quote, make up a quote yourself, and
indicate that it is your own quote.
(8.) Write a function that prints all the vowels in that quote, and returns the count.
(9.) Write a function that prints all the consonants in that quote, and returns the count.
Textbook Questions
(10.) C++ Variables:
Question (24.) on Page 463
(11.) Statistics:
Question (12.) on Page 456
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for C++
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for c++ programmer, you might be surprised that even for entry level positions
for a C++ Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with C++
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in C++ and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in C++ and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
C# Function: Exercises, Practice, Solution
(https://www.w3resource.com/csharp-exercises/function/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(12.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
Java Methods: Exercises, Practice, Solution
(https://www.w3resource.com/java-exercises/method/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(13.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
(1.) Review the post (Discuss Questions) done by your colleagues.
Use a different statement to work on the same function used by your colleague.
For example: if your colleague used an iteration statement in a function, you may use a conditional statement or a
jump statement or a different iteration statement to write the same function to give the same output.
(2.) Review the post (Discuss Questions and Assess Questions) done by your colleagues.
If your colleague developed a console application for a program, develop a desktop application for the same program.
If your colleague developed a desktop application for a program, develop a console application for the same program.
(3.) Other substantive responses.
Algebra: Questions (1.) through (4.)
(1.) Please review the Roots of a Quadratic Equation on the Expressions and Equations website:
Quadratic Equations
(www.expressions-equations.appspot.com/#quadraticEquations)
There is a calculator I developed that calculates the roots of a quadratic equation and displays a message.
(I.) Write a function that requests the user to input the three values: (as seen on my calculator), and
display the same message that is displayed by my calculator.
In other words, the output and message from your calculator should be the same as the output and
message from my calculator when the user inputs those three values.
Test your program for each of the four cases of the discriminant regarding the nature of the roots
of a quadratic equation as seen in Numbers (1a.), (1b.), (2.) and (3.) on my website.
(II.) Submit clear screenshots of your program.
(III.) Submit clear screenshots of the output of your program for the four cases.
(IV.) Submit clear screenshots of the output of my calculator for the four cases.
(III.) and (IV.) should display the same messages.
(2.) Algebra:
Question (28.) on Page $464$ of your textbook.
(3.) Algebra:
Question (16.) on Page $458$ of your textbook.
(4.) Algebra: Piecewise Functions
Question (14.) on Page $457$ of your textbook.
data, array, list, container, data container, index, element, member, iterators, For Loop, While Loop, Do-While Loop, Range-based For Loop, length, size, sort, sorting techniques,
Students will:
(1.) Discuss arrays.
(2.) Sort arrays.
(3.) Write programs that use arrays.
(4.) Pass arrays as function parameters.
(1.) Textbook Chapter
(2.) Tutorials by cplusplus.com: Arrays and Character sequences
(https://www.cplusplus.com/doc/tutorial/arrays/)
(3.) Tutorials by w3schools: Arrays
(https://www.w3schools.com/cpp/cpp_arrays.asp)
(4.) Tutorials by Microsoft: Arrays(C++)
(https://docs.microsoft.com/en-us/cpp/cpp/arrays-cpp?view=msvc-170)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(5.) Type C++ Array in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(6.) Type C++ Array in the search bar and view/read the results.
dataType arrayName [array length] = {array elements};
dataType arrayName [] = {array elements};
dataType arrayName [array size] {array elements};
int numbers[5] = {1, 3, 7, 9, 10};
Notice that: array[index] = element
numbers[0] = 1 numbers[1] = 3 numbers[2] = 7 numbers[3] = 9 numbers[4] = 10For an array of size, $n$;
for (dataType variable : arrayName) { statement; }Example 1: Array of the perfect squares of the first positive ten integers
Range-based For Loop | For Loop, While Loop, Do-While Loop |
---|---|
(1.) Loops through each array element without using a counter. | (1.) Loops through each array element using a counter. |
(2.) The length of the array is not needed. | (2.) The length of the array is needed. |
Determining the Length/Size of an Array
There are at least three approaches to determining the size of an array.
We demonstrated the first approach in Example 1: size(array)
This approach require that we include the array
library or the algorithm
library
Then, we use the size function
Let us review the second approach of finding the length of an array.
This approach uses a formula.
We do not need to include any additional library besides the input-output stream library
Example 2: Second Approach to determine the length of an array
Given an array of the first seven negative integers
Print the third element of the array
Determine the length of the array
Example 3: Third Approach to determine the length of an array
This approach require that we include the Iterator
library or the array
library
Then, we have to subtract the index of the first element from the index of the last element
Student: So, if we replaced the iterator library with the array library,
the program will still work?
Teacher: Yes, the program will display the same output.
Student: This approach deals with an arithmetic operation just like the second approach.
I think the best approach is the first approach.
Just have to remember to include the array library
Teacher: That is correct.
We have another way to determine the length of an array...using Pointers
Student: What is a pointer?
Is that method easier?
Teacher: A pointer is a form of an iterator
We shall discuss it in details in the next module.
Let us review an example.
Example 4: Fourth Approach to determine the length of an array
This approach uses Pointers.
Length of array = *(&array + 1) - array
Include the iterator library or the array library
Student: This approach is the worst approach.
Teacher: Well, it will not be that bad when we discuss Pointers
However, it is not the easiest approach.
When we declare an array of a specific size; we can include some elements as we declare the array and include the
remaining elements later.
In other words, we can add elements to an existing array provided the remaining elements would not exceed the size
of the array at declaration.
Say we want a seven-member array.
We shall declare an array length of seven
Let us include four elements at declaration.
Then, we can include the remaining three elements to the array.
Example 5: Add elements to an existing array.
Print the array.
We can replace element(s) in an existing array.
We just have to use array index to replace the element(s).
Example 6: Replace elements in an existing array.
We can remove elements from an existing array.
Example 7: Remove elements in an array.
We remove/delete an element from an array by setting the index of that element to an empty array
array
library to determine the size, alternatively; we can use the
algorithm
library. sort(array, array + arraySize)Example 8: Sort an array of integers in ascending order.
sort(array, array + arraySize, greater<dataType of array>())Example 9: Sort an array of integers in descending order.
Statistics comprises Data Analysis.
Data Analysis is part of Data Science.
Data Science is part of Computer Science/Programming.
As a programmer, it is very likely that you will deal with data.
In this course, we shall focus only on some of the Descriptive Statistics of Data Analysis.
The Descriptive Statistics that we shall discuss in this course are:
(1.) Measures of Center:
Also known as the Measures of Central Tendency
They are the: Mean, Median, Mode, and Midrange.
(2.) Measures of Spread:
Also known as the Measures of Dispersion or the Measures of Variability or the Measures of Variation
For this course, we shall focus on the: Range, Variance, and Standard Deviation.
(3.) Measures of Position:
Also known as the Measures of Location
For this course, we shall focus on the: Five Number Summary of Data
They are the: Minimum, First Quartile, Second Quartile, Third Quartile, and Maximum.
The First Quartile is also known as the Lower Quartile or the 25th Percentile
The Second Quartile is also known as the Median or the Middle Quartile or 50th Percentile
The Third Quartile is also known as the Upper Quartile or 75th Percentile
Let us write program examples of descriptive statistics using C++
The formulas used are the formulas on the Descriptive Statistics website
(1.) Formulas for the Measures of Center
(2.) Formulas for the Measures of Variation
(3.) Formulas for the Measures of Location
Example 11: Data Analysis: Descriptive Statistics of Raw Ungrouped Data with C++
Let us do an example that uses an Input-Output Feature
Ask the user how many numeric values that he/she would like to enter.
Store the values in an array.
In this case, it is better to write a function.
Write that a function that computes the descriptive statistics of the array.
TextBook Questions
(1.) Question (1.) on Page 604
(2.) Question (2.) on Page 604
(3.) Question (3.) on Page 604
(4.) Question (4.) on Page 605
For Questions (5.) and (6.);
Review these Sorting Techniques and Algorithms
(https://www.samdomforpeace.com/DataStructures/Sorting.html)
(5.) Write a function (user-defined function) that sorts an array in ascending order using any of the techniques.
Use an array size of at least 3 (array size $\ge 3$).
Specify the technique.
(6.) Write a function (user-defined function) that sorts an array in descending order using any of the techniques.
Use an array size of at least 3 (array size $\ge 3$).
Specify the technique.
(7.) Write a function (user-defined or system-defined function) that divides an even-sized unsorted array into two equal halves, sorts the
first half in ascending order, and sorts the second half in descending order.
Use any even size of at least 8 (array size $\ge 8$).
(8.) Write a function (user-defined or system-defined function) that divides an even-sized unsorted array into two equal halves, sorts the
first half in descending order, and sorts the second half in ascending order.
Use any even size of at least 8 (array size $\ge 8$).
C++ Programming Exercises, Practice, Solution by W3Resource
Please review:
C++ Array: Exercises, Practice, Solution
(https://www.w3resource.com/cpp-exercises/array/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(9.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write clear comments for each line of code in the Solution.
Run the program.
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for C++
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for c++ programmer, you might be surprised that even for entry level positions
for a C++ Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with C++
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in C++ and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in C++ and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
Java Array: Exercises, Practice, Solution
(https://www.w3resource.com/java-exercises/array/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(10.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
C# Array: Exercises, Practice, Solution
(https://www.w3resource.com/csharp-exercises/array/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(11.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
JavaScript Programming Exercises, Practice, Solution by W3Resource
Please review:
JavaScript Array: Exercises, Practice, Solution
(https://www.w3resource.com/javascript-exercises/javascript-array-exercises.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(12.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
JavaScript Programming Exercises, Practice, Solution by W3Resource
Please review:
JavaScript Searching and Sorting Algorithm: Exercises, Practice, Solution
(https://www.w3resource.com/javascript-exercises/searching-and-sorting-algorithm/index.php)
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(13.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in C++
Run the program. Please make sure your program output is the same solution
(1.) If your collegue used a for-loop in the program, please rewrite the same program to give the same
output using a while loop or do-while loop or range-based loop
(2.) If your colleague did not use a function in the program, please use a function with the array and rewrite
the same program to give the same output.
(3.) If your colleague used a function but did not use array as a parameter, please use the function and the
array as a parameter, and rewrite the same program to give the same output.
(4.) Other substantive responses.
For Questions (1.) through (4.), you may develop a console application or a desktop application.
(1.) Please review the Solved Examples on the Measures of Center
Find any question that has Ungrouped Data with frequency.
(a.) Write a program that computes the measures of center for that question.
Test the program output with the results on the
Descriptive Statistics Calculators
(b.) Solve the question.
Check your answer with the solution on the website.
(2.) Please review the Solved Examples on the Measures of Spread
Find any question that has Ungrouped Data with frequency.
(a.) Write a program that computes the measures of dispersion for that question.
Test the program output with the results on the
Descriptive Statistics Calculators
(b.) Solve the question.
Check your answer with the solution on the website.
(3.) Please review the Solved Examples on the Measures of Position
Find any question that has Ungrouped Data with frequency.
(a.) Write a program that computes the measures of location for that question.
Test the program output with the results on the
Descriptive Statistics Calculators
(b.) Solve the question.
Check your answer with the solution on the website.
(4.) Please review the Solved Examples on Descriptive Statistics
Find any question that has Ungrouped Data with frequency.
(a.) Write a program that computes the measures of center and/or the measures of variability and/or the measures of position for that question.
Test the program output with the results on the
Descriptive Statistics Calculators
(b.) Solve the question.
Check your answer with the solution on the website.
vary, variable, data type, data value, value, container,
Students will:
(1.)
(2.)
(1.) Textbook Chapter
(2.) Pointers and Dynamic Memory
(https://www.cplusplus.com/doc/tutorial/pointers/)
(3.) References and Pointers
(https://www.w3schools.com/cpp/cpp_references.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ References and Pointers in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ References and Pointers in the search bar and view the results.
(1.)
(1.)
There are three options for your Final Exam.
Please choose only one option.
This option is based on your textbook (MindTap course).
This implies that it is not free.
However, you have two-weeks free access.
So, it is free if you can complete all the graded assessments in two weeks.
Please click the Gradebook and complete all the assessments there.
The assessments that are automatically graded count for the Final Exam.
The assessments that are to be manually graded count for the Final Project.
Access the MindTap Course
Course Key: MTPQ5FCQWR2M
This exam is designed to assess your understanding of the advanced C# concepts.
You have reviewed several topics and several concepts in each topic for eight modules.
Pick at least $1$ concept in at least $1$ topic in each of the $8$ modules.
That gives at least $8$ concepts in $8$ different topics in $8$ modules.
Find two more concepts in any topic in any module.
That gives $10$ concepts.
For each concept, please:
(1.) Write at least three sentences about that concept.
(2.) Develop a program about that concept.
In other words, write at least one code example about the concept.
Run the code.
Display the output.
Submit clear screenshots of your program (code and output)
Deliverables:
(1.) $10$ concepts in $10$ different topics for $8$ modules
Please write the: Module number, the Topic, and the Concept
(2.) Three sentences for each concept.
(3.) Code for each concept.
(4.) Output for each concept.
Please submit all these information as a zipped folder (.zip only) in the Final Exam folder of the Blackboard course.
There are four options for your Final Project.
Please choose only one option.
This option is based on your textbook (MindTap course).
This implies that it is not free.
However, you have two-weeks free access.
So, it is free if you can complete all the graded assessments in two weeks.
Please click the Gradebook and complete all the assessments there.
The assessments that are automatically graded count for the Final Exam.
The assessments that are to be manually graded count for the Final Project.
Access the MindTap Course
Course Key: MTPQ5FCQWR2M
It is important you communicate with me for approval prior to doing this project.
Because the course deals with only desktop applications and console applications,
(rather than web applications and mobile applications), you may not do any project that requires a web server
such as contact forms and registration forms among others.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Think about any of these companies: our Institution: Kent State University; your local campus; your work place; public and
private schools (excluding home schools); organizations, firms, and businesses
(excluding controversial firms and the like).
Any company you choose should have a verifiable website.
The direct link of the company's website is required.
(2.) Identify a problem on the website that you want to solve.
The problem must be solved by programming using the knowledge acquired from any of the course
topics/concepts/description/learning objectives.
Think about your Midterm Project. You solved a problem: calculating bills, federal taxes, etc.
(3.) Develop the computer program to solve the problem.
Test the program to ensure that it works.
Write detailed comments as applicable.
(4.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What problem did you identify?
Did you solve the entire problem or part of the problem?
What course topics/concepts/description/learning objectives did you apply in solving the problem?
How did you solve the problem?
Did you encounter any issues while trying to solve the problem?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Program (all files)
(2.) Clear screenshots of your program (code and output)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zipped folder (.zip only) in the Final Project folder of the Blackboard course.
The final project is designed to assess your understanding and analysis of data using the knowledge you have
acquired in the course.
Please:
(1.) Visit my website on: Descriptive Statistics
(2.) Review the information for a good understanding of Descriptive Statistics.
It is highly likely that you have a prior knowledge of this topic. Is that right?
(3.) Click the Project link.
(4.) Review the Project Examples. Ensure you follow all the instructions and directions.
(5.) Complete the Final Project for your course.
(6.) Ask questions. I can help.
If you have any issue at any time and you have reviewed the resources I provided and you cannot fix the issue,
please attend the Office Hours/Live Sessions so I can help you.
(7.) Include all these: (documentation of all your Math work and the .exe file) in OneDrive, create a
shareable link, and post the link in the Final Project Drafts forum of the course on Blackboard or send to me via email.
You may also upload them directly if you prefer.
I shall review and provide feedback.
(8.) When you are done with your project:
Make sure your executable file runs by itself outside the project folder
If it does run, include these three items: single executable file (that runs by itself outside the folder), the
Math documentation (Word document that has the Math part), and the entire project folder, into a folder,
zip the folder (.zip extension only) and submit it in the appropriate area of the Blackboard course.
If it does not run, please fix it.
If you cannot fix it, please attend the Office Hours/Live Sessions so I can help you.
NOTE: Any actual project submitted to me via email will not be graded.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Your Midterm Project is a Console Application.
If you did your midterm project very well and you want to develop a C++ desktop application for the same
application, please go ahead.
Test the program to ensure that it works.
Write detailed comments as applicable.
(2.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What did you do?
Did you encounter any issues?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Executable file.
(2.) Program folder (all folders and files)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zip file (.zip only) in the Final Project folder of the Blackboard course.
NOTE: Any actual project submitted to me via email will not be graded.
Course using C++ classes and data abstraction, stream IO, inheritance, standard template library, Microsoft Foundation Classes, system programming concepts using Unified Modeling Language. Prerequisite: IT 20001
By the end of this course, you should be able to do the following:
(1.) Explain the concepts of classes and data abstraction.
(2.) Demonstrate programming techniques, control structures, functions, arrays, pointers, strings, classes,
inheritance, stream IO, exception handling, and sequential file processing.
(3.) Employ appropriate data structures.
(4.) Utilize the Unified Modeling Language.
Students will:
(1.) Write programs that uses vector functions.
(2.) Write programs that demonstrates vector applications.
array, vector, index, size, length, position
(1.) Textbook Chapter
(2.) Vector Functions
(https://www.cplusplus.com/reference/vector/vector/)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(3.) Type C++ Vectors in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(4.) Type C++ Vectors in the search bar and view/read the results.
vector<int> numbers = {1, 3, 7, 9, 10};Notice that:
vector[index] = elementThis means that:
numbers[0] = 1 numbers[1] = 3 numbers[2] = 7 numbers[3] = 9 numbers[4] = 10For a vector of size, $n$;
Please review the examples of Vector Functions (vector member functions links on the Left Hand Side of that page).
(1.) Besides the examples discussed in the reading, please write a program demonstrates any other vector functions.
Explanation and formulas for the Measures of Center and
Measures of Spread
(2.) Write a program that demonstrates all the relational operations between two vectors.
(3.) Ask the user to input numerical data of any size.
Define your data.
Compute the measures of center of the data.
Question (3.) counts for both post and response.
(4.) Ask the user to input numerical data of any size.
Define your data.
Compute the measures of spread of the data.
Question (4.) counts for both post and response.
(1.) Provide a substantive response to the initial post of any of your colleagues.
(1.)
Students will:
(1.) Discuss the terms used in object-oriented programming.
(2.) Create a class.
(3.) Create a constructor.
(4.) Implement different constructors.
(5.) Overload constructors.
(6.) Create a destructor (destroy a constructor).
(7.) Discuss the properties of a class
(8.) Implement the various properties in a class.
(9.) Develop a console application that implements classes, objects, constructors, and properties.
object-oriented programming, class, object, namespace, access specifier, scope operator, scope resolution operator, class member, variable, data type, field, property, attribute, method, function, functional form, assignment initialization, uniform initialization, plain old data (POD), get, get accessor, getter, set, set accessor, setter, void, parametized constructor, auto-implemented property, expression-bodied definition property, exceptions, throw an exception, encapsulation, reference, dependency, event, event handler, backing store, command line interface (CLI), backing store, C++/CX (the CX means a set of extensions to the C++ language for the Windows Runtime Environment)
(1.) Textbook Chapter
(2.) Classes (I)
(www.cplusplus.com/doc/tutorial/classes/) and
Special members
(www.cplusplus.com/doc/tutorial/classes2/)
(3.) C++ Classes: C++ OOP to
C++ Access Specifiers
(www.w3schools.com/cpp/cpp_oop.asp)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type Object-oriented Programming in C++ or OOP in C++ in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type Object-oriented Programming in C++ or OOP in C++ in the search bar and view/read the results.
Teacher: So, we discussed data types and variables
We did some work/calculations with the data types and variables.
Our project started to grow.
We needed to lessen codes and reuse codes. Simply put, we wanted to do more with less.
We introduced functions to achieve that goal.
Functions included the data types, variables and the work/calculations done with
them.
The project started getting large and popular. It needed to serve more clients.
What should we do?
Can we join data types, variables and functions as a package? Can we reuse that package as
much as we want?
The answer is Yes!
Welcome to Classes
Student: Where did the object-oriented come from?
Teacher: Good question.
Remember how we call a function any time we want to use that function?
We shall 'call the class', well create a new instance of the class anytime we want to use that class.
So, whenever we create an instance of the class because we want to use that class, we have created an
object
That means that an object is an instance of the class.
Student: So, what you are saying is that an object is simply calling the class in order to use it?
Just like we do in functions?
Teacher: That is correct.
Simply put, creating an object means calling the class.
We can create as many objects as we want by calling a class anytime we want.
The class is a package of data types, variables and functions.
Actually, a class is a package of fields, methods, and properties.
Creating and using objects to develop computer programs is known as object-oriented
programming.
Encapsulation is the combination of fields, properties, methods, and events of an object
in a class(capsule).
In other words, keep all the data and program logic in one place.
Student: You introduced some words.
Teacher: Yes, I did.
No worries you will get used to them.
The field is the data type and variable.
The field is often referred to as an attribute.
The method is a function
The property allows us to change the fields.
The fields, properties, and methods are referred to as the class members
A class in C++ is declared using the class keyword.
Class names are written in uppercase or Pascal case.
The basic syntax for creating for a class in C++ is:
class NameofyourClass { access specifier: fields; };
Let us do some examples.
What is my first greeting to my students?
Welcome to our IT 36301: Advanced C++ Programming class!
So, let us create a class called ComputerScience
The field in the class will be the greeting. It is a string.
Example 1: Welcome to our IT 36301 Class: Advanced C++ Programming Class!
In this example; we:
Created a class, ComputerScience.
Defined a field in that class, string greeting
Used the access specifier, public with that field in order to access the variable, greeting
outside the ComputerScience class.
Created a new instance of the class, otherwise known as an object; student1 in the main class,
Program.
Greeted that student object, student1 with the greeting we defined in the ComputerScience
class by joining the object with the variable using the member access expression, . (the
period punctuation mark).
Student: This is what I don't get.
Why use public?
Teacher: We used public so we could access that variable, greeting outside the
class that it was defined.
If we used private, we would not be able to access the variable outside that class.
See what I mean.
We can create two objects (two students) and greet them.
The teacher should greet the student.
Create a class that has three members: two fields and one method.
The teacher and the student should be fields.
The greeting should be the method.
Create an object (an instance of the class) in the main class.
The object in the main class should call the method from the created class so that the teacher greets the
student.
In this program, we created and defined the method inside the class.
We can create the method inside the class but define it outside the class.
Then, we create the object and still use that method.
Let us write Example $3$ in another way. We shall still get the same output.
As you noticed, we had to make the method to be public so we could access it outside the class we
created.
NOTE: In the case that we define the method outside the class, we have to use the scope resolution operator
to connect it to the class.
The scope resolution operator is also known as the scope operator.
It is the two colon symbols ::
It has several uses. However, in this case; it is used to define a class member outside the class.
As you can see; the method, greeting was created inside the class.
But, we defined it outside the class using the scope resolution operator
So, the scope resolution operator is used to define a method outside a class if the method was created inside the class.
Student: What if we decided not to make it public or private?
Teacher: Good question.
In that case, the members would be private.
Class members in C++ are private by default.
Student: So, I guess we have only private and public access specifiers?
Teacher: We have some more.
Let us list them.
Then, we can discuss each of them as we progress through the course.
An Access specifier is a keyword used to declare the accessibility of a class member or
type.
It is used to control the visibility and security level of a class or class member.
The first name of a person can be made public. However, the person's SSN (social security number) should not be
made public.
A person's social security number should shoud of course, be made private.
Similarly, there are some class members that can be made public and there are some that should not be
made public.
In C#, we have three access specifiers.
They are:
Access Modifier | Accessibility Level |
---|---|
public | Access is not restricted. The class member can be assessed outside the class that it was created. |
private | Access is limited to the containing type. The class member can only be assessed within the class it was created. |
protected | Access is limited to the containing class or types derived from the containing
class. The class member can be assessed within the class it was created, or in a class that is inherited from the class that it was created. |
NOTE:
(1.) If an access specifier is not specified for a class member, that class member is private by default.
Student: What if students want to greet their fellow students?
Teacher: Good question.
This means that we need to expand our program.
As we add more requirements, the program starts getting large.
But, we do need to simplify the program.
So, let us begin by having separate files for this program.
Let us create another file for our class; a header file.
We shall add the header file to our main program.
Let us name that file, ComputerScience.h
So, we will have two files: Classes.cpp (that contains the main method) and
ComputerSCience.h (that contains our class: the ComputerScience class).
Keep in mind we already created this class.
We just want to put it in another file so it is separate from the main method.
Then, we can add as many members as we want.
We already demonstrated how to add a header file in Module 6 of the pre-requisite course: Functions
Let us demonstrate another way to add a header file in this module.
The steps in creating the ComputerScience.h class are:
In the Solution Explorer window (the window on the Right Hand Side) of the Visual Studio IDE:
(1.) Right-click the Header Files folder
(2.) Point your mouse on the Add menu
(3.) Click the New Item submenu.
(4.) Click the Header File (.h) submenu under Visual C++.
(5.) Name the header file: ComputerScience.h
Please see images below.
Whenever you make any change in either file; please ensure that you:
(1.) Save All then you
(2.) Build the solution. If the Build succeeded (as should be seen in the message on your computer),
then you
(3.) Run the solution.
If there were build errors, you should review the line numbers where those errors occurred, as
well the errors.
Fix the errors, build the solution again, and run the solution.
Going forward, we shall be creating and defining our methods inside the class.
But, you may choose to create it inside the class, and define it outside the class. Just be sure not to forget the scope operator.
Back to your question:
We want students to greet themselves.
We already know that Chukwuemeka is the teacher and Samuel is the student.
Let's say we want another student, Dominic.
The teacher would greet the two students, Samuel and Dominic.
Each student will greet the other as well.
In other words:
Chukwuemeka will greet Samuel
Chukwuemeka will greet Dominic
Samuel will greet Dominic
Dominic will greet Samuel
So, we have four greetings of "Welcome to our Class!"
Student: What if we have different names for the teachers and students?
Do we need to keep defining each name as a field when we have a new teacher and new students?
Teacher: Good question.
More functionalities means that we should find a way of achieving the same output with less code.
This leads to...
What we can do to address your question is to create a constructor.
A constructor in C++ is a special method that is: always public;
has the same name as the class; used to initialize objects; and
does not return values.
Hence, whenever we create an object (the instance of the class), the constructor is called.
The constructor is a method. So, it needs to have an access specifier. That access specifier must be public.
Note that it should have the same name as the class name.
So, you can say that is a special method because it has an access specifier, has the same name as the
class name, may or may not have parameters that would be defined as initial variables or values of the class
members, and does not return any value.
There is always at least one constructor in every class.
If a class is created without a constructor, the compiler creates a default constructor for that class.
C# constructors are:
(1.) Default Constructor
(2.) Parametized Constructor
public: className() { statement; }Let us implement a default constructor
public: ClassName(parameter1, parameter2, ...) { statement; }We shall use parametized constructors frequently in the course.
Notable Notes for C++ Classes and Constructors:
I hope it does not confuse you. It is not my
intention to confuse you. It's C++ 😊
(1.) When you define a class, you must put a semicolon at the end of the curly braces of that class.
(2.) When you define a constructor inside a class,
do not put a semicolon at the end of the parenthesis containing the parameters.
(3.) When you declare a constructor inside a class, but define it outside the class, you must put a
semicolon at the end of the parenthesis containing the parameters inside the class.
(4.) When you declare a constructor inside a class, but define it outside the class using the scope
resolution operator, do not put a semicolon at the end of the parenthesis containing the parameters outside the class.
(5.) When you define constructors, do not put a semicolon at the end of the parenthesis containing the
parameters.
(6.) When you define constructors, do not put a semicolon at the end of the curly braces of the constructor.
So, the only cases you should be careful are Numbers (1.) and (3.)
The good thing is that several IDEs will display an error if you forget to include the semicolon.
(7.) Do not put parenthesis whenever you create an object that calls the default constructor.
Use parenthesis only when you create an object that calls a parametized constructor
We can overload constructors
This implies that we can create two constructors with the same name but different parameters.
NOTE: This is based on what I have found out.
To overload two or more parametized constructors:
(1.) If you use the same parameter data type and the same number of parameters for one constructor, do
not use that same parameter data type and number of parameters for the other constructor (overloaded constructor).
For example: If you use the string data type for three parameters in the first constructor, do not use the
string data type and three parameters for the other constructor.
You may use the string and integer data types for three parameters for both constructors (because they are different data types).
In addition, you may use the string data type and three parameters for the first constructor, and the string data
type but two parameters for the second constructor (because the number of parameters are different).
(2.) The number of parameters in the constructors must not be the same.
Let us overload two parametized constructors.
Teacher: Did you notice the functionality of overloaded constructors?
We can change the parameters with ease.
We can write a short story/poem/drama about KSU among others.
Student: What if we wanted the parameter data type and the number of parameters in both
constructors to be the same?
Can we do that?
Teacher: What do you think?
Student: I don't know. That's why I asked.
Teacher: Yes, we can.
But, one of constructors would be a default constructor and the other constructor would be a
parametized constructor.
The default constructor would have fields (with the same data type), rather than parameters.
The parametized constructor would have parameters with the same data type as the fields in the default
constructor.
Let's do it.
Let us overload a default constructor and a parametized constructor.
Laugh it off: 😊 😊 😊
First constructor, come here....Nigerian way
Second constructor, where are you?...Nigerian way
Third constructor, where ya at?...American way...southern style
Fourth constructor, fourth constructor, fourth constructor!...Nigerian way
Fifth constructor, where art thou?...British way...
Okay, B2B (Back to Business)
We can call constructors in four different ways namely:
(1.) Functional form.
This is what we have been using for calling the constructors with no parameter, and one or more parameters.
We enclose the arguments in parenthesis when we create the object.
The syntax is: ClassName object (argument1, argument2, ...)
(2.) Assignment Initialization
This is only used for constructors with only one parameter.
The object is assigned to a single argument/value.
The syntax is: ClassName object = argument
(3.) Uniform Initialization
This is used to call constructors with one or more parameters.
However, the arguments are enclosed in curly braces when we create the object.
The syntax is: ClassName object {argument1, argument2, ...}
(4.) POD-like form (Plain Old Data-like form)
This is used to call constructors with one or more parameters.
However, the object is assigned to arugments in curly braces.
The syntax is: ClassName object = {argument1, argument2, ...}
Let us demonstrate each of those forms.
A property is a public class member that can read, write, or
compute the value of a private field.
Just like a constructor, a property is also a method.
So, it needs an access modifier.
That access modifier must be public.
The accessors are the: get accessor and the set accessor.
In other words, the get and set parts of a property are called accessors.
As mentioned in the previous module: Encapsulation is the combination of fields, properties, methods, and
events of an object in a class(capsule).
Encapsulation is also used to hide sensitive data from users.
The main objective of using Properties is for encapsulation in terms of
hiding sensitive data from users.
Recall: that a class member is private by default if we do not specify an access modifier for it.
It is also private if we specify the private access modifier for it.
If we need to access that private class member outside the class, we have to use a property.
C++ does not natively support properties.
But, we can still write properties in C++. We shall do.
On the other hand, C++/CX (the CX means a set of extensions to the C++ language for the Windows Runtime Environment)
natively supports properties.
We have several properties and types of properties in C++/CX.
To learn about them, and how to use them, please review:
Properties
and How to Use Properties in in C++/CLI as regards C++/CX
Let us demonstrate the features and functions of properties.
Let us demonstrate the Read-Write property in C++.
Please review the comments in each example for further explanations.
Let us get back to the greeting example.
The teacher greets the student.
We shall use a constructor.
The getter and setter are used. How are they used?
The get keyword and the set keyword are used as prefixes in combination with the name of the property.
Remember that Property names begin with uppercase letters.
You write: getPropertyName and setPropertyName
The get assessor returns the value of the variable name.
The set assessor takes a parameter (new name) and assigns it to the variable name.
Please review the code.
Review the explanations in the comments.
Please review the BMI information on these two government websites [from the Center for Disease Control and Prevention (CDC) and the National Heart, Lung, and Blood Institute of the National Institutes of Health (NIH)]
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC and
Calculate Your BMI - Standard BMI Calculator
As at today, the 3rd day of September, 2020; the BMI information on both websites are:
NIH website
Calculate Your BMI - Standard BMI Calculator
CDC website
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC
$ BMI = \left(\dfrac{weight}{height * height}\right) * 703 \\[5ex] weight\:\:is\:\:in\:\:pounds (lb) \\[3ex] height\:\:is\:\:in\:\:inches (in) $
$ BMI = \left(\dfrac{weight}{height * height}\right) \\[5ex] weight\:\:is\:\:in\:\:kilograms (kg) \\[3ex] height\:\:is\:\:in\:\:meters (m) \\[3ex] $ If you need help with conversion of units, please review the Tables and Examples in Measurements and Units
Teacher: What do you notice in both websites?
Student: They both have the information on the BMI.
In addition, the CDC website has information for both Adult BMI and Child & Teen BMI among others.
The NIH website has recommendations among others.
Teacher: That is correct. What else?
Student: They have the BMI calculator.
Teacher: Did you notice any difference in the calculator on both websites?
Student: The NIH website has BMI calculator for both Standard and Metric versions.
The CDC website has the BMI calculator for only the Metric version.
Teacher: Did you notice any issue/concern about the BMI information?
Student: Not really. Why?
Teacher: So, this is what we are going to do.
Let us develop the BMI calculator.
That calculator will calculate the BMI.
Then, we shall interpret that BMI, and make a recommendation.
.
The CDC website gave us the formula for calculating the BMI. So, we shall use it.
As you can see, our calculator would have to use conditional statements for the interpretation and recommendation.
But, here is the issue.
Student: Wait, I think I see the issue.
The issue is with the domains.
Teacher: Correct!
Anyone having a BMI between $18.5$ and $24.9$ both endpoints included has a Normal weight.
This is: Normal weight: [18.5, 24.9]. It is a closed interval (relate with Mathematics).
So, the Overweight range for the BMI should be the weight greater than $24.9$, (rather than beginning from $25$) and ending at $29.9$
For the Overweight range, the first endpoint is not included, but the second endpoint is included.
This is: Overweight: (24.9, 29.9]. It is a half-open half-closed interval (relate with Mathematics)
Teacher: Do you know why this would be a problem if the programmer does not fix these issues before developing the calculator?
Student: Yes. Because there would not be any interpretation for anyone whose BMI is between $24.9$ and $25$
But, I do see that the BMI information is for values rounded to one decimal place.
Teacher: That is correct.
And we shall develop our calculator to round to one decimal place.
But, it is important we fix the issues.
What if we do not want to round?
Look at the two examples on the CDC website. The BMI values were rounded to two decimal places.
If we developed our calculator to round to two decimal places with the information on those websites "as is"; then we would not have the interpretation and recommendation for those two examples ($24.98$ and $24.96$) because those values are greater than $24.9$ but less than $25$.
Student: That makes sense.
So, the last one: Obese should be BMI greater than $29.9$, rather than greater than $30$?
Teacher: That is correct.
So far, we discussed:
(1.) Methods (Functions) in C# Programming
(2.) Introduction to Object-oriented Programming (Classes, Constructors, and Objects) in Module 1.
(3.) Properties in this module: Module 2.
Let us apply what we learned so far.
We shall develop a console application and a desktop application for the Body Mass Index (BMI) calculator.
(1.) The program should accept user inputs of:
(I.) First name
(II.) Last name
(III.) Weight
(IV. Height
(2.) The program should output the:
(A.) BMI value
(B.) Interpretation
(C.) Recommendation
(3.) The program should address user-input errors of non-positive numbers for the weight and the height.
Inform the user.
Then, exit the program without causing it to crash.
(1.) We shall create a new project: Module2
The main file (the file that contains the main method) will be named Module2.cpp
(2.) Because the first name and the last name is not needed in the calculation, we shall ask for the user input of
first name and last name in the main method
(3.) We shall create a header file under the project.
I prefer creating class in a header file and including it in the main method of Module2.cpp, rather than creating the class inside the
Module2.cpp.
I like to separate my programs. However, do what you prefer.
So, we shall create a header file, BodyMassIndex.h and create the class, BodyMassIndex in that header file.
Then, we shall include the header file in Module2.cpp
Teacher: You know something I learned in America...as regards dating?
Student: What is it?
Teacher: You should not ask a woman her weight.
Student: LOL. Is that all you learned?
Teacher: Another thing is that you should not ask a woman her age.
But, a woman can ask a man his age.
Student: That is correct. In America, you do not ask a woman her weight or her age.
Teacher: Is that not double standard?
Anyway...B2B (back to business)
(4.) We shall create two fields: weight and height for our class: BodyMassIndex
Because we shall associate the weight and height with the user's first name and last name, we shall declare
these fields as private.
Be reminded that even if you do not specify an access modifier for the fields, they are declared as private by default.
However, it is good practice to specify access modifiers.
(5.) We shall create public properties for these private fields so we can access them.
Because the setter does not return anything, we need to use the void data type for it.
The setter does have the parameter of the double data type of the variable corresponding to each field.
We shall use the double data type in the getter to return each field.
(6.) We shall create a parametized constructor that will initialize the class fields.
Here is something to note: Use the same parameter that you used in each setter as the parameters for the constructor.
Assign the fields to the constructor parameters.
(7.) We shall create a method: BodyMassIndexDetails
This method is necessary to calculate the BMI.
We need to add some checks to make sure that only positive values are entered for the user input weight and
height.
Zero and negative values should not be allowed.
No worries. We shall disuss Exception Handling in details in another module. For now, please learn a simple way of
doing that check in this application.
In addition, we shall interpret the BMI and make recommendation based on the calculated BMI value.
We shall create three more variables in the method: one variable for calculating the BMI;
another variable for interpreting the BMI; and the third variable for recommendation based on the BMI.
(8.) Go to the main method in the Module2.cpp and ask for user input of the first name, last
name, weight, and height
NOTE:
We will declare variables for: first name, last name, weight, and height in the Main method.
However, we shall use the constructor parameters as the same variables for weight and height
In other words: our constructor parameters are: weightPounds and heightInches
We shall use that weightPounds and heightInches as our variables.
Also: we shall use that weightPounds and heightInches as the arguments when we create the
object.
Recap:
We shall use weightPounds and heightInches and their data types as the parameters for the constructor in our BodyMassIndex class.
We shall use the same weightPounds and heightInches and their data types when we declare variables in the Main method.
We shall still use the same weightPounds and heightInches (without the data types) as our arguments in our object.
Create the object: calculateBMI
Display your summary and make it look nice.
To underline anything in the console window:
\x1B[4m is the code to underline.
\x1B[0m is the code to end the underline (reset).
Use the object to call the method.
(9.) Test your program for each piece/case.
In other words, test your program to ensure that the calculation, interpretation, and recommendation is correct for
all the BMI options.
You may also test the examples on the CDC website.
(10.) Test your program to check for user input errors.
Please see the images.
Review the comments.
Results:
Check for User Input Error:
(1.) Write a program for a scenario/case/example where you would:
(I.) Implement any of the constructors that we discussed.
(II.) Use a combination of at least two different data types for the class fields.
This implies that you should have at least two class fields of different data types.
(2.) Write a program that overloads at least two constructors.
(3.) Review the last example on Calling Constructors.
Look at this screenshot
How can you fix the two warnings?
Fix the warnings.
Run the program.
Display the same output.
(4.) Review Member initialization in constructors
Write a program that demonstrates member initialization in constructors.
Run your program.
Display the output.
(5.) Review Pointers to classes
Write a program that demonstrates pointers to classes using all those expressions.
Run your program.
Display the output.
(6.) Review Overloading operators
Write a program that demonstrates the overloading of operators to classes of vectors (no structures please: the struct keyword).
Run your program.
Display the output.
(7.) As we mentioned earlier, C++/CX natively supports properties.
However, we did not discuss those properties.
Review these websites regarding Properties
and How to Use Properties in in C++/CLI as regards C++/CX
Write programs that demonstrates each kind of property and type of property.
Run your programs.
Send the screenshots of each output.
For Questions (8.) and (9.)
Class, Property, Constructor, Method
(I.) Consider any concept/scenario that uses conditional statements.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Use a class you created.
(IV.) Use at least one private field.
(V.) Use properties that should access that private field.
(VI.) Use at least one method.
(VII.) Include some checks for user input errors.
(VIII.) Test your program and display the result/output for each condition.
(IX.) Test your program for user-input errors.
(X.) Submit all the screenshots in your DB 2 forum on Blackboard.
(8.) Develop a console application for your concept.
(9.) Develop a desktop application for your concept.
(1.) If your colleague developed only a console application, develop the desktop application for that concept.
(2.) If your colleague developed only a desktop application, develop the console application for that concept.
(3.) Other substantive responses.
For Question (1.)
Class, Property, Constructor, Method
(I.) Consider any concept/scenario that uses conditional statements.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Use a class you created.
(IV.) Use at least one private field.
(V.) Use properties that should access that private field.
(VI.) Use at least one method.
(VII.) Include some checks for user input errors.
(VIII.) Test your program and display the result/output for each condition.
(IX.) Test your program for user-input errors.
(X.) Submit all the screenshots in your DB 2 forum on Blackboard.
(1.) Develop a console application and a desktop application for your concept.
One application will count for DB Post.
The other application will count for DB Response.
You do not need to respond to the initial post of another colleague.
Please specify which one should count for DB Post and DB Response.
(2.) Develop a console application for an extension of my concept (the BMI application).
I did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
(3.) Develop a desktop application for an extension of my concept (the BMI application).
I did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Your desktop application should have the dropdown list for both systems, but should be null be default.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(2.) Type C++ Exception and/or C++ Exception Handling in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(3.) Type C++ Exception and/or C++ Exception Handling in the search bar and view/read the results.
The midterm project is designed to assess your knowledge of Object-oriented Programming in solving real-world problems.
It is a Piecewise Function application.
Any other application will not considered.
Please:
(1.) Visit my website on: Piecewise Functions
(2.) Read the Story to understand the idea of Piecewise functions.
(3.) Read the Overview of Piecewise Functions for more understanding of Piecewise functions.
(4.) Study the Applications of Piecewise Functions
(5.) Review the Project Examples. Ensure you follow all the instructions and directions.
(6.) Review the Midterm Project rubric for your course.
(7.) Complete the Midterm Project for your course.
(8.) Ask questions. I can help.
If you have any issue at any time and you have reviewed the resources I provided and you cannot fix the issue,
please attend the Office Hours/Live Sessions so I can help you.
(9.) (7.) Include all these: (documentation of all your Math work and the .exe file) in OneDrive, create a
shareable link, and post the link in the Midterm Project Drafts forum of the course on Blackboard or send to me via email.
You may also upload them directly if you prefer.
I shall review and provide feedback.
(10.) When you are done with your project:
Make sure your executable file runs by itself outside the project folder
If it does run, include these three items: single executable file (that runs by itself outside the folder), the
Math documentation (Word document that has the Math part), and the entire project folder, into a folder,
zip the folder (.zip extension only) and submit it in the appropriate area of the Blackboard course.
If it does not run, please fix it.
If you cannot fix it, please attend the Office Hours/Live Sessions so I can help you.
NOTE: Any actual project submitted to me via email will not be graded.
If you wish to save some time for research:
Please review the Piecewise Function projects done by my previous students.
The direct link of the verifiable websites are included.
(I.) VB Projects
(II.) C# Projects
(III.) C++ Projects
(IV.) Java Projects
You may not do any same application done by any of my previous students for C++
You may do any Piecewise Function application not done by any of my previous students for C++
If you are not sure what project you may or may not do, please contact me via the school email.
inherit, inheritance, friend, friend functions, friend classes, behavior, data, class members, colon symbol :, parent class, base class, superclass, child class, derived class, extended class, subclass, final keyword, virtual keyword, override keyword, interface, abstract class, single inheritance, multiple inheritance, multilevel inheritance, transitive inheritance, concrete class, interface, abstract class
Students will:
(1.) Discuss the inheritance of a class.
(2.) Discuss polymorphism in object-oriented programming.
(3.) Write programs that demonstrate the inheritance of a class.
(4.) Write programs that demonstrate polymorphism.
(1.) Textbook Chapter
(2.) C++ Inheritance
(www.w3schools.com/cpp/cpp_inheritance.asp)
and
C++ Polymorphism
(www.w3schools.com/cpp/cpp_polymorphism.asp)
(3.) Friendship and Inheritance
(www.cplusplus.com/doc/tutorial/inheritance/)
and
Polymorphism
(www.cplusplus.com/doc/tutorial/polymorphism/)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type C++ Inheritance and Polymorphism in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(5.) Type C++ Inheritance and Polymorphism in the search bar and view/read the results.
There are three primary characteristics/pillars of object-oriented programming:
(1.) Encapsulation
(2.) Inheritance
(3.) Polymorphism
A teacher, Mr. C with his three students: Student $1$, Student $2$, and Student $3$
The students are dual enrolled high school students.
They are bold and smart.
They are taking a Computer Science course with Mr. C
Teacher: Today, we shall be discussing Inheritance
Student $1$: Is this a Zoology class?
Teacher: Why do you ask?
Student $2$: Why do you answer questions with questions?
Teacher: Typical of Nigerians :-)
It saves you from getting into trouble.
Student $1$: I asked because we are studying Genetics.
Teacher: Interesting.
So, we can use some interdisciplinary knowledge from both courses.
My first question is:
What did you inherit from your parents: Dad, Mom, Grand Dad, Grand Mom (Father's side), Grand Dad, Grand Mom
(Mother's side), several generations on both sides, atavism?
Student $2$: What do you mean by atavism
Student $3$: It's a reappearance of an ancestral trait.
For example: Remember those Nigerian parents (both of them are Black) that gave birth to a white baby girl?
One of the reasons the doctors gave was dormant white genes which entered both of the female's parents'
families long ago.
That is atavism.
You can read the story online. Wait: here is the link from CBS News:
(https://www.cbsnews.com/news/white-baby-shocks-black-parents-medically-possible/)
Student $1$: CBS News? LOL
Teacher: Hey, do not say what you want to say.
This is not politics.
Student $1$: And what if I do?
Student $3$: Some other news sources have it as well.
Teacher: Okay guys, you have not answered my question.
Student $2$: Well, as you can see: I have blonde hair and blue eyes.
But surprisingly, my parents have brown hair and brown eyes.
Why is that?
Student $1$: Your parents have the dominant brown hair and brown eyes genes and the recessive blond
hair and blue eyes genes.
They passed those recessive genes to you.
Student $2$: Interesting.
But, if I want my children to have those dominant brown hair and brown eyes genes, what should I do?
Student $1$: Let me just invite you to our Biology course so you ask those questions.
I am still learning.
But, just pray for it. Do not do anything to try to disrupt nature.
Teacher: Okay, get back on track to my questions.
Student $3$: I inherited intelligence from my parents.
Student $1$: So, we had this argument in class: Is intelligence acquired or inherited?
Is it by nature or nature or both?
Teacher: Intelligence is both nature and nurture though it is more of nurture.
Student $1$: What are your reasons, Sir?
Teacher: You have two Nigerian parents, did not attend school did not have any formal education; yet
their children are the best graduating medical students.
Student $1$: Well, the fact that they did not attend school does not mean that they are not
intelligent. Someone who is not literate can still be intelligent. I think intelligence is wisdom.
Student $3$: I inherited tallness from my Mom.
My Mom is tall and my Dad is of average height.
Teacher: I am still waiting for your answer.
Student $1$: Who? Me?
Teacher: Yes of course.
Student $1$: I think I inherited my temperament from my Dad.
Teacher: Bold. Reactive (not proactive). High activity level. Persistent.
Student $1$: You got it.
But, you do know environmental factors contribute as well.
Teacher: Yes I know.
Just like Intelligence, Temperament is both nature and nurture. However, it is more of nurture.
Student $1$: Now, back to you, Mr. C
What did you inherit from your parents?
Teacher: Oh come on.
Can't you see it?
Everyone is looking at me.
Student $1$: Meaning?
That I am a very handsome man.
Everyone starts smiling/laughing
It's good to laugh and be relaxed before we start learning some codes.
Student $1$: We are looking at you because you are the professor.
Teacher: And because I am very handsome.
Alright, B2B...
Everyone says: Back to Business
So as you can see (based on our discussion), one can inherit traits from the Dad, Mom, Mom and Dad,
grandparents, or even ancestral traits.
So far:
In your previous course: the Beginner's course; we discussed
(1.) Method/Function
In the previous modules for this course, we discussed:
(1.) A class
(2.) Constructor
(3.) Property
Say that we created a class: Class $A$ with some members: fields, properties, and methods
We want to create another class: Class $B$ and use the members from class $A$ and also use additional
members
Keep in mind that class members includes fields, properties, and methods.
Rather than create Class $B$ and define all those members from Class $A$, we can create Class $B$ as a child of
Class
$A$ so that it inherit the class members from Class $A$ and then create the additional members for it.
We can also create Class $C$ to inherit some of the properties of Class $A$ and also some of the properties of
Class $B$
So, you can see it this way:
Class $A$ as the parent
Class $B$ as the child
Class $C$ as the grandchild
Remember one inherits the genes of grandparents and great grand parents and so on and so forth. The amount
depends on the percentage or fraction. (which you discuss in Genetics).
Welcome to Inheritance.
Inheritance is the ability of a class to inherit the members of another
class
The class whose members are inherited from another class is known as the base class or parent
class or superclass
The class that inherits the class members from another class is known as the derived class or
child class or extended class or subclass.
So, this is seen as:
Base class and Derived class OR
Base class and Extended class OR
Parent class and Child class OR
Superclass and Subclass (Compare to Superset and Subset in Algebra)
(Please get used to these words because we shall be using them interchangeably.)
Superclass and Subclass are preferred terms for the Java programming language.
The main purpose of inheritance is to reuse, extend, and modify the class members of a parent class by the
child class.
It allows one to define a child class that reuses (inherits), extends, or modifies/overrides the behavior of a parent class.
When a class is derived from a base class, the derived class implicitly gains all the members of the base class,
besides its constructors, destrcutors, assignment opeartor members, friends, and private members.
The derived class reuses the code in the base class without having to reimplement it.
You can add more members in the derived class.
The derived class extends the functionality of the base class.
public class DerivedClass : public BaseClass(2.) C++ supports multiple inheritance of base classes.
// First Base Class class BaseClass1 { ... } // Second Base Class class BaseClass2 { ... } // Third Base Class class BaseClass3 { ... } // Derived Class class DerivedClass : public BaseClass1, public BaseClass2, public BaseClass3 { ... }Let us demonstrate multiple inheritance with the Golden Dox.
Let us discuss some advantages of Inheritance.
(1.) Code Reusability: As seen in the previous examples, we reused the class fields of the base class.
Inheritance is like the DRY (Don't Repeat Yourself) of programming because some class members of the base
class are reused.
Reusability leads to reduced development and maintenance costs.
(2.) Code Extensibility: Inheritance allows for modification and extension of code.
As seen in the previous examples, we modified and extended the fields that was inherited from the base
class, in the derived class.
(3.) Creation of Class Libraries: Inheritance facilitates the creation of class libraries.
(4.) Access to protected class members of the base class:
So far, we have:
(a.) Used the public access specifier.
(b.) Used the private access specifier.
Recall that we had to use Property to access a private class field.
But, what about the other access specifier: protected. We have not used it.
We shall use it in this module.
Recall that in the: protected access specifier: Access is limited to the containing class or types
derived from the containing class.
The class member can be assessed within the class it was created, or in a class that is inherited
from the class that it was created.
The protected class members are similar to private class members. However, they can be
inherited.
So, we shall be using the protected access specifier for any class member that we want to
encapsulate.
Please note that: we still need to use Properties to access protected class members because technically,
they are still 'private'.
The only difference is that they can be inherited by derived class while private class members cannot be
inherited.
So, they will be inherited. But, we shall use Properties (setter and getter) to access them.
Let us demonstate the use of the protected access specifier.
Let us do some math calculations.
Simple Interest and Amount Calculations
Please review Question (5.) and the solution on Solved Examples on
Simple Interest website:
(www.finance-calculators.appspot.com/simpleInterestApplications.html)
Let us calculate the simple interest and amount for several customers.
We shall use Inheritance to solve that Question for several students.
We shall make the interest rate of the financial institution and the time to be public, but make the first
names of the customers and the principal (sum of money deposited) to be protected.
Please review the screenshots and the comments.
(1.) Coupling of the base class and the derived class: The derived class is dependent on the base class to
the degree that any change in the base class affects the derived class.
Imagine if one deletes a class member of a base class that is also used in the derived class.
For instance, in our demonstration of Multilevel Inheritance; if one of the properties of the Quadrilateral is
deleted, the program will not run.
(2.) Execution time (Run time): It takes more time for an inherited method to execute when compared to a
method that did not use inheritance.
One can write a program that uses a class to calculate the simple interest and amount of an investment without using
inheritance.
(3.) Depending on the compiler, unused base class members is a waste of memory: When a derived class inherits
a base class, it may or may not use all the inherited class members of the base class.
In the event that any base class member is not used in the derived class, it leads to a waste of resource/memory
allocated to that class member. This typically depends on the compiler.
Notice that in our examples, we did not use all the fields of the base class.
So far, we demonstrated the inheritance of the class fields of the base class.
But remember: the methods of the base class can also be inherited.
We discussed the Third Approach to Inheritance
However, in that approach; the base class method and the derived class method had different names:
BaseClassDetails() and DerivedClassDetails().
What if they have the same name and we want different outputs for both methods, what should we do?
We can:
(1.) Declare the method in the base class with the virtual keyword and declare
the method in the derived class with the override keyword.
Then, create two objects: one object of the base class to call the base class method and and another object
of the derived class to call the derived class method.
By doing so, we can run the methods in both the base class and the derived class.
An example is the event that occurred in July 2020 when Governor Brian Kemp of the U.S State of Georgia banned cities and counties from enforcing a mask mandate.
(www.cbsnews.com/news/georgia-governor-brian-kemp-bans-city-face-mask-orders-coronavirus-pandemic/)
In essence, the governor's executive order of not requiring masks overrides any law/ordinance by cities and counties
requiring masks.
Let us assume (and of course the assumption is proper) that the City of Atlanta inherits from the State of Georgia.
Let us demonstrate the use of the virtual and override keywords
Please review the screenshots and the comments.
Same method name: virtual keyword in the base class method and override keyword in the derived class method
NOTE:
The use of the virtual and override keywords is not required in C++ (at least for this example and many examples we shall do in this course).
This program will still run without the use of virtual and override keywords.
A nice feature of C++?
Student: So, what is the need for those keywords?
Teacher: Good question.
We do need to use the virtual keyword when we discuss Pointers to a Base Class and Abstract Base Classes in Polymorphism
Abstraction is the process of hiding sensitive data while exposing only the required properties and methods.
Compare it to a situation where we have a private class field, but use a public property to access that field
(the Get and Set accessors).
Abstraction is done using:
(1.) The private and/or protected access specifiers. (We have demonstrated examples of these uses).
(2.) Abstract class
Literally: poly means many and morphs means forms; so polymorphism means
many forms
Polymorphism is the ability of classes to:
(I.) Invoke the methods of a derived class by referencing a base class at run time and
(II.) Implement different methods called by the same name at compile time
There are basically two kinds of polymorphism:
(1.) Dynamic Polymorphism
(2.) Static Polymorphism
This polymorphism:
(1.) Occurs at run time
(2.) Also referred to as late binding polymorphism because the decision regarding the method to be called
is made at run time.
(3.) Overrides the method of a base class by using the same name and parameters of that method in a
derived class in order to perform a different task. (Method Overriding)
Let us demonstrate Dynamic Polymorphism
Back to Geometry: Quadrilaterals
A Quadrilateral is a four-sided polygon.
These figures are Quadrilaterals.
(1.) Square
(2.) Rhombus
(3.) Rectangle
(4.) Parallelogram
(5.) Kite
(6.) Trapezoid
We shall calculate the perimeter of these quadrilaterals.
The formulas for calculating the perimeters of quadrilaterals are found here:
Mensuration Formulas
(www.samuelchukwuemeka.com/Mensuration/formulas.html)
The website also contains the calculators for calculating perimeters.
You may test the output of this program with the Mensuration Calculators
on the website.
We shall list the parameters used for calculating the perimeters of the quadrilaterals.
The parameters are the class fields of the base class: Quadrilateral.cs
Main Class: Program.cs
Base Class: Quadrilateral.cs
Child Class: Square.cs
Child Class: Rectangle.cs
Child Class: Rhombus.cs
Child Class: Parallelogram.cs
Child Class: Trapezoid.cs
Child Class: Kite.cs
To calculate the perimeter of a:
(I.) Square and Rhombus: only a side is needed.
So, we shall define side as one of the class fields of the Quadrilateral
(II.) Rectangle and Parallelogram: the length and the width is needed.
So, we shall include length and width as class fields of the Quadrilateral
(III.) Kite: A kite has two pairs of equal sides.
We shall define them as side1Kite and side2kite and include them as class fields of the Quadrilateral
(IV.) Trapezoid: A trapezoid has no equal side.
The Quadrilateral class fields for these sides are: side1Trapezoid, side2Trapezoid, side3Trapezoid,
and side4Trapezoid
The other class fields we need for the Quadrilateral.cs class are the fields that define the perimeters for each
quadrilateral.
Let us demonstrate Dynamic Polymorphism (Polymorphism at Run-time)
Please review the screenshots and the comments.
Dynamic Polymorphism (Polymorphism at Run-time)
This polymorphism:
(1.) Occurs at compile time
(2.) Also referred to as early binding polymorphism because the decision regarding the method to be called
is made at compile time.
(3.) Overloads the method of a class by using the same name but different number and/or parameter types of
that method in a
class in order to perform different tasks. (Method Overloading)
For this to occur, the method in the class must not have the same number and parameter type to perform
those different tasks.
(4.) Overloads the operator of a class to perform different tasks. (Operator Overloading)
Static Polymorphism consists of Method Overloading and Operator Overloading.
Let us demonstrate Method Overloading in Static Polymorphism.
Let us just focus on Rectangle.
Another property we shall add is that each angle in a Rectangle is a right angle. (an angle of 90 degrees).
We shall overload the methods with different parameter data types: (integer data type to calculate the sum of the
interior angles in a Rectangle; string data type to list the properties of a Rectangle; and two double data types to
calculate the perimeter of a Rectangle).
We can also have a parameterless method to list the properties of a Rectangle rather than using the string data type
as a parameter.
Please review the screenshots and the comments.
Static Polymorphism: Method Overloading
Let us demonstrate Operator Overloading of the Addition Operator, $+$ in Static Polymorphism.
So, we need objects that will be added.
Still working with Rectangles, let us calculate the sum of the Perimeters of Two Rectangles.
The formula for calculating the perimeter of a rectangle is found here:
Mensuration Formulas
(www.samuelchukwuemeka.com/Mensuration/formulas.html)
The website also contains the calculators for calculating perimeters.
You may test the output of this program with the Mensuration Calculators
on the website.
Please review the screenshots and the comments.
Static Polymorphism: Operator Overloading
Quick Question for you.
Please choose the correct option.
Which is the correct option for the explanation of the sum of the perimeters of the rectangles we
calculated using Addtion Operator Overloading?
Give at least one reason for your answer.
(A.) $7$ unit is the length and $3$ unit is the width of the first rectangle.
Using the formula in the method, we got $20$ unit as the perimeter of the first rectangle.
$14$ unit is the length and $10$ unit is the width of the second rectangle.
Using the same formula, we got $48$ unit as the perimeter of the second rectangle.
Then, we overloaded the addition operator to add the two perimeters in order to get the sum.
The sum of the perimeters of the two rectangles is $68$ unit because it is the result of the addition of
$20$ unit and $48$ unit.
(B.) $7$ unit is the length of the first rectangle and $14$ unit is the length of the second rectangle.
We overloaded the addition operator to get the sum of the lengths as $21$ unit.
$3$ unit is the width of the first rectangle and $10$ unit is the width of the second rectangle.
We overloaded the addition operator to get the sum of the widths as $13$ unit.
Then, we used the formula in the method to get the perimeter.
That perimeter is the sum.
(C.) Options (A.) and (B.) are both correct.
(D.) Does it really matter? The main thing is that the answer is correct.
$48$ unit is the sum of the perimeters of the two rectangles.
The correct option is $B$
If you did not answer Option $B$, please review the screenshots and the comments again.
Then, let me know if you have any questions.
Some operators can be overloaded while some cannot.
Let us review those operators that can and cannot be overloaded.
(1.) Use any academic field/discipline/area of your interest.
Find any topic(s) in that discipline that you are knowledgeable about/proficient in.
With clear explanations and comments, write programs that demonstrate:
(a.) Inheritance
(b.) Multiple Inheritance
(c.) Multilevel Inheritance
Submit clear screenshots of the codes and the outputs.
Cite your source(s) accordingly.
(2.) Use any academic field/discipline/area of your interest.
Find any topic(s) in that discipline that you are knowledgeable about/proficient in.
With clear explanations and comments, write programs that demonstrate:
(a.) Dynamic Polymorphism
(b.) Method overloading in Static Polymorphism
(c.) Operator overloading in Static Polymorphism
Submit clear screenshots of the codes and the outputs.
Cite your source(s) accordingly.
(1.) Rewrite the program of your colleague to display the same output.
(2.) Other substantive responses.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.) Grade Point Average (GPA) Calculation for Several Students
Please review Question (7.) on the website: Solved Examples on the Measures of Center
(www.descriptive-statistics.appspot.com/measuresCenter.html)
Review the steps in calculating Rita's GPA.
Use only the five courses listed in the example.
Make the fields: first name and the grade of the student to be protected
You are welcome to make other fields public if you wish.
Write a C++ program that uses Multilevel Inheritance to calculate the GPA of Rita and at least one other student simultaneously (at the same time)
Use the same numbers in Question (7.) to calculate Rita's GPA.
For the other student, use a fictitious name or Nameless; and use every grade: $A, B, C, D, F$ in the calculation.
For example: the student should make an $A$ in one course, a $B$ in one course, a $C$ in one course, a $D$ in one course
and an $F$ in one course.
The output of your program should include the information in the table as seen in the solution for Question (7.):
(a.) the name of the student
(b.) the each course and the grade for each course
(c.) the corresponding point for the grades
(d.) the credit hour for each course
(e.) the sum of the credit hours
(f.) the corresponding grade points
(g.) the sum of the grade points
(h.) the GPA
Do you understand the information in that table?
The user (student) should be able to look at your output and understand the GPA calculation very well.
These are the minimum requirements.
You may wish to give recommendation and advice among others to the user/student based on the grade and/or the GPA.
Submit clear screenshots of your program (all codes and the output).
(2.) Question Number (4.) of Chapter (11.) in Page Number $812$ of your textbook.
Submit clear screenshots of the question and your program (all codes and the output).
(3.) Question Number (5.) of Chapter (12.) in Page Numbers $891$ and $892$ of your textbook.
Submit clear screenshots of the question and your program (all codes and the output).
(4.)
template, type parameters, non-type parameters, function template, class template, template specialization, template parameters, template arguments, standard template library, components, containers, container class templates, sequence containers, array, vector, deque, forward list, list, linked list, associative containers, set, trees, multiset, map, associative arrays, multimap, unordered associative containers, unordered set, unordered multiset, unordered map, unorderd multimap, container adaptors, stack, last-in first-out (LIFO) context, queue, first-in first-out (FIFO) context, priority queue, heap
Students will:
(1.) Discuss templates.
(2.) Write programs that use templates.
(3.) Discuss the standard template library.
(4.) Implement the methods of the container class templates of the standard template library.
(1.) Textbook Chapter
(2.) Templates
(www.cplusplus.com/doc/oldtutorial/templates/)
(3.) Containers
(www.cplusplus.com/reference/stl/)
(4.) Templates
(www.docs.microsoft.com/en-us/cpp/cpp/templates-cpp?view=vs-2019)
(5.) Standard Library Containers
(www.docs.microsoft.com/en-us/cpp/standard-library/stl-containers?view=vs-2019)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(6.) Type Standard Template Library and/or C++ Templates in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(7.) Type Standard Template Library and/or C++ Templates in the search bar and view/read the results.
The Standard Template Library is the set of class templates used as a generic class library
for programming.
It consists of four container class templates.
Each container class templates consists of several class templates.
The container class templates and their respective class templates are:
(1.) Sequence Containers
(I.) Array
(II.) Vector
(III.) Double Ended Queue (Deque)
(IV.) Forward List
(V.) List
(2.) Associative Containers
(I.) Set
(II.) Multiset
(III.) Map
(IV.) Multimap
(3.) Unordered Associative Containers
(I.) Unordered Set
(II.) Unordered Multiset
(III.) Unordered Map
(IV.) Unordered Multimap
(4.) Container Adaptors
(I.) Stack
(II.) Queue
(III.) Priority Queue
DB Requirement Number (3.) is required.
Please submit clear screenshots of your program (codes and outputs)
Sequence Containers
Besides arrays (which we covered in the Beginning C++) and vectors (which we covered in Module $1$ of this Advanced C++);
please implement any five member functions of:
(1.) Double ended queue (Deque)
(www.cplusplus.com/reference/deque/deque/)
(2.) Forward List
(www.cplusplus.com/reference/forward_list/forward_list/)
(3.) List
(www.cplusplus.com/reference/list/list/)
Associative Containers
Please implement any five member functions of:
(4.) Set
(www.cplusplus.com/reference/set/set/)
(5.) Multiset
(www.cplusplus.com/reference/set/multiset/)
(6.) Map
(www.cplusplus.com/reference/map/map/)
(7.) Multimap
(www.cplusplus.com/reference/map/multimap/)
Unordered Associative Containers
Please implement any five member functions of:
(8.) Unordered Set
(www.cplusplus.com/reference/unordered_set/unordered_set/)
(9.) Unordered Multiset
(www.cplusplus.com/reference/unordered_set/unordered_multiset/)
(10.) Unordered Map
(www.cplusplus.com/reference/unordered_map/unordered_map/)
(11.) Unordered Multimap
(www.cplusplus.com/reference/unordered_map/unordered_multimap/)
Container Adaptors
Please implement any five member functions of:
(1.) Stack
(www.cplusplus.com/reference/stack/stack/)
(2.) Queue
(www.cplusplus.com/reference/queue/queue/)
(3.) Priority Queue
(www.cplusplus.com/reference/queue/priority_queue/)
Important
Please include this information as comments in your program:
(1.) Container Class Template:
Identify the container class template of the Standard Template Library (STL)
Is it Sequence container? Associative container? Unordered associative container? Container adaptor?
(2.) Class Template:
Identify the class template of the container class template.
For example: if you are working on sequence containers, is it deque, forward list, or list?
(3.) Member Function:
Please write each member function as comment before implementing it.
Include any other additional necessary comments.
DB Requirement Number (3.) is required.
(1.) Using a different container class template, class template, and member function; implement
at least one (one or more) member functions implemented by any of your colleagues.
Please submit clear screenshots of your program (codes and outputs)
Important
Please include this information as comments in your program:
(1.) Container Class Template:
Identify the container class template of the Standard Template Library (STL)
Is it Sequence container? Associative container? Unordered associative container? Container adaptor?
(2.) Class Template:
Identify the class template of the container class template.
For example: if you are working on sequence containers, is it deque, forward list, or list?
(3.) Member Function:
Please write each member function as comment before implementing it.
Include any other additional necessary comments.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.) Measures of Center and Measures of Dispersion of Data
Please give an appropriate name for your dataset.
An even-sized dataset and an odd-sized dataset is required.
Calculations of the measures of center and the measures of spread are required.
Please test your program for an even-sized dataset and an odd-sized dataset.
Submit clear screenshots of the codes and outputs for both.
Please review the:
Measures of Center
(www.descriptive-statistics.appspot.com/#formulasMeasuresCenter)
and the:
Measures of Spread
(www.descriptive-statistics.appspot.com/#formulasMeasuresSpread)
and the:
Examples of the Final Project for the Measures of Center and the Measures of Spread
(www.descriptive-statistics.appspot.com/project.html)
(I.) Using any member function of any class template of the standard template library and any dataset that
has at least a size of six (sample size of $6$) for an even-sized dataset; calculate the measures of center
and the measures of spread of the dataset.
(II.) Using any member function of any class template of the standard template library and any dataset that
has at least a size of six (sample size of $7$) for an odd-sized dataset; calculate the measures of center
and the measures of spread of the dataset.
You can use any made-up dataset for this assignment.
However, for your final project; your dataset must be verifiable.
file, stream, iostream, input/output stream, istream, cin, input stream, ostream, cout, output stream, fstream, file stream, ofstream, output file stream, ifstream, input file stream,
Students will:
(1.) Write a program that creates a text file and writes text to the text file.
(2.) Write a program that appends text to the text file.
(3.) Write a program that reads from the text file.
(4.) Implement member functions of file streams.
(5.) Write a program that creates a binary file and writes binary data to the binary file.
(6.) Write a program that reads from the binary file.
(1.) Textbook Chapter
(2.) Input/Output with Files
(www.cplusplus.com/doc/tutorial/files/)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(3.) Type C++ Files and Streams in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(4.) Type C++ Files and Streams in the search bar and view/read the results.
open
to open a file. open (filename, mode)where:
filename
is a string representing the name of the file. mode
is an optional parameter.
Mode Parameter | Instruction |
---|---|
ios::in |
Open for input operations |
ios::out |
Open for output operations |
ios::app |
Append content to the end of the current content of the file |
ios::trunc |
Erase all current content from the file and replace with new content |
ios::ate |
Set the initial position at the end of the file |
ios::binary |
Open in binary mode |
Notable Notes on the open
function
(1.) Some or all of the mode parameters can be combined with the use of the bitwise operator OR, |
(2.) The default mode parameter for the ifstream class is ios::in
(3.) The default mode parameter for the ofstream class is ios::out
(4.) The default mode parameter for the fstream class is ios::in | ios::out
(5.) For the ifstream class and ofstream class, their default mode parameters are automatically
assumed even if a mode that does not include them is passed as second argument to the open
function.
In that case, the flags are combined.
(6.) For the fstream class, the defualt value is applied only if the open
function is called
without any values for the mode parameters.
If the function is called with any value in the parameters, the default mode is overridden. It is not combined.
(7.) By default, the initial position is set at the beginning of the file.
However, using the mode: ios::ate
sets the initial position at the end of the file.
Even though the mode parameter is optional, I recommend that you use them.
Actually, the parameters are required in some cases.
We shall review those cases where they are required and where they are optional.
Nonetheless, I shall use them in our examples.
Closing Files
It is important to close any file you opened, when you are done with it.
To close a file: use the syntax: filename.close()
When the close
function is called:
(1.) The operating system makes its resources available again.
(2.) The stream object can be re-used to open another file.
(3.) The closed file is available to be opened and used by other processes.
If an object that is associated with an open file is destroyed, the destructor automatically calls the
close
function.
Let us do some examples.
Pick any topic in an academic area/field/discipline of your choice.
I am going to write some notes about the topic we shall study in the next module:
Microsoft Foundation Class (MFC)
But, you may choose whatever you want, provided it is in an academic discipline.
The limitation of using this approach to read a file is that you must save the text file in a particular location
before it can read.
The steps are:
(1.) Create a text file about the topic: say Module7Notes.txt
(2.) Write some notes in the file.
This is what I wrote:
Microsoft Foundation Class (MFC) includes the global functions, global variables, classes, and macros that make up the Microsoft Foundation Class Library.
The Microsoft Foundation Class Library is:
(1.) An application framework for developing programs in Microsoft Windows.
(2.) Written in C++.
(3.) Used to develop desktop applications including applications with Office-style user interfaces.
The Microsoft Foundation Class Framework:
(1.) Reduces development time.
(2.) Makes code portable.
(3.) Simplifies database programming through Open Database Connectivity (ODBC).
(4.) Simplifies network programming through Windows Sockets.
(5.) Gives easy access to "hard to program" user-interface elements and technologies such as Internet programming among others.
(4.) Review the examples.
Review the screenshots and the comments.
Important: Please make sure you save your file where the IDE would access it.
When you created the C++ application, you named the application.
I named my application: FileStream
Go to the location of your application. My applications are in the Documents folder of my C: drive.
Click the application folder: FileStream
Then, drop your text file Module7Notes.txt there.
WindowsC: ---> Users ---> chukw ---> Documents ---> C++ ---> FileStream ---> Module7Notes.txt
The location is: C:\Users\chukw\Documents\C++\FileStream\Module7Notes.txt
With this approach, you:
(1.) Save the text file only in the application folder.
(2.) Create a string variable that will be used to read the file.
(3.) Create an object of the ifstream class
(4.) Use the object to open the file with the member function open.
You may or may not include ios::in as the mode parameter.
I prefer to include it but you do not have to include it.
With this approach, the mode parameter is optional.
(5.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
Student: I do not like this approach.
The file path stuff for the file.
Why can't I just save my file wherever I want it to be?
Teacher: You are not alone.
I do not like it either.
Let us look at another approach.
In that second approach, you can save your file where you like and read it from there.
I prefer this approach.
We can save our file whereever we want on the C: drive, and read it from there.
So, we shall copy the file: Module7Notes.txt from where we saved it and save it in a new location.
The easy way to figure out the path/location of your file is: Right-click the file; click the Properties icon; and
copy the Location. You do want to make sure you include the file name to the path in the program.
The new location is: C:\Users\chukw\OneDrive\Documents\C++\FileStream\Module7Notes.txt
However, please note:
For C++: Because we are using the Microsoft path separator in a literal string, we need to include the backslash
escape sequence in the file path.
That means that the new location is:
C:\\Users\\chukw\\OneDrive\\Documents\\C++\\FileStream\\Module7Notes.txt
As you can see: I saved it in the FileStream folder of the C++ folder of the Documents File and folder of the
OneDrive on my computer.
Yes, I saved it in the cloud.
Yes, I can make changes to it (append some texts to it) in the cloud.
With this approach, you:
(1.) Save the text file whereever you wish to save it.
(2.) Create a string variable that will be used to read the file.
(3.) Create an object of the ifstream class
(4.) Use the object to open the file with the member function open.
Include ios::in as the mode parameter.
With this approach, the mode parameter is required.
(5.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
The steps are:
(1.) Create an object of the ofstream class
(2.) Create the text file by writing to it.
You may or may not include ios::out as the mode parameter.
I prefer to include it but you do not have to include it.
With this approach, the mode parameter is optional.
It is optional with this approach because the text file is saved in the application folder by default.
(3.) Write some text to the file.
(4.) Close the file.
We have created the file.
The file has been saved in the application folder by default.
We have written some text to it.
Please go to the application folder in your computer and verify.
Now onto reading the file...
(5.) Create a string variable that will be used to read the file.
(6.) Create an object of the ifstream class
(7.) Use the object to open the file with the member function open.
You may or may not include ios::in as the mode parameter.
I prefer to include it but you do not have to include it.
With this approach, the mode parameter is optional.
(8.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
Let us do some History with this approach.
Let us use the Preamble from the Declaration of Independence
(www.archives.gov/founding-docs/declaration)
We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator
with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.
-Preamble to the Declaration of Independence
Please review the screenshot and the comments.
With this approach, we want to save the file in our location of choice on the C: drive.
The steps are:
(1.) Create an object of the ofstream class
(2.) Create the text file by writing to it.
We must include ios::out as the mode parameter and specify the location that we want to save it.
With this approach, the mode parameter is required.
Let us save it in this location: C:\Users\chukw\OneDrive\Documents\C++\FileStream\Elements.txt
However, please note:
For C++: Because we are using the Microsoft path separator in a literal string, we need to include the backslash
escape sequence in the file path.
That means that the new location is:
C:\\Users\\chukw\\OneDrive\\Documents\\C++\\FileStream\\Elements.txt
(3.) Write some text to the file.
(4.) Close the file.
We have created the file.
The file has been saved in the location of our choice.
We have written some text to it.
Go ahead and verify that the file exists in that location.
Verify the contents as well.
Now onto reading the file...
(5.) Create a string variable that will be used to read the file.
(6.) Create an object of the ifstream class
(7.) Use the object to open the file with the member function open.
Include ios::in as the mode parameter.
With this approach, the mode parameter is required.
(8.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
Student: Which example will you use this time?
Teacher: Guess what I'm thinking?
Student: What?
Teacher: About a mnemonic we learned in Junior Secondary School in Nigeria
Junior Secondary School in Nigeria is equivalent to Middle School in the United States.
Student: What is the mnemonic?
Teacher: The mnemonic that helped us to write the first twenty elements of the Periodic Table?
I even made a YouTube video about it.
Student: Interesting.
Where is the video?
Can you write the elements off hand?
Teacher: Sure \smile
The link is: 1st 20 Elements of the
Periodic Table>
Let us write the first the mnemonic, the element, and the symbol for the first twenty elements.
Let's do it.
The steps are:
(1.) Create an object of the ofstream class
(2.) Create the text file by writing to it.
You may or may not include ios::out as the mode parameter.
I prefer to include it but you do not have to include it.
With this approach, the mode parameter is optional.
It is optional with this approach because the text file is saved in the application folder by default.
(3.) Write some text to the file.
(4.) Close the file.
We have created the file.
The file has been saved in the application folder by default.
We have written some text to it.
Please go to the application folder in your computer and verify.
Now onto appending some text to the file...
(5.) Create an object of the ofstream class
(6.) Append some text to the file.
You need to include ios::app as the mode parameter.
Including it is important so it does not overwrite the text already written.
(7.) Append some text to the file.
(8.) Close the file.
Now onto reading the file...
(9.) Create a string variable that will be used to read the file.
(10.) Create an object of the ifstream class
(11.) Use the object to open the file with the member function open.
You may or may not include ios::in as the mode parameter.
I prefer to include it but you do not have to include it.
With this approach, the mode parameter is optional.
(12.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
Let us do some Civil Rights History with this approach.
Let us use one of the quotes from Martin Luther King Jr.
"Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that."
- Martin Luther King, Jr.
Please review the screenshot and the comments.
The steps are:
(1.) Create an object of the ofstream class
(2.) Create the text file by writing to it.
We must include ios::out as the mode parameter and specify the location where we want to save it.
With this approach, the mode parameter is required.
However, please note:
For C++: Because we are using the Microsoft path separator in a literal string, we need to include the backslash
escape sequence in the file path.
That means that the new location is:
C:\\Users\\chukw\\OneDrive\\Documents\\C++\\FileStream\\LivingThings.txt
Student: What are you up to, Mr. C?
Teacher: Hmmmm...the name of the file?
Student: Yes...
Teacher: Let's do an application in Biology for this example.
Guess what we learned in the Elementary School in Nigeria.
Student: What is it?
Teacher: The characteristics of living things.
We used this acronym: MRNIGER for the characteristics of living things
M: Movement
R: Respiration
N: Nutrition
I: Irritability
G: Growth
E: Excretion
R: Reproduction
Let us write the first four characteristics: MRNI to the file: LivingThings.txt
Then, we append the remaining characteristics: GER to the file.
(3.) Write some text to the file.
(4.) Close the file.
We have created the file.
The file has been saved in OneDrive...the location of our choice.
We have written some text to it.
Please go to the folder in the OneDrive of your computer and verify.
Now onto appending some text to the file...
(5.) Create an object of the ofstream class
(6.) Append some text to the file.
We need to include ios::app as the mode parameter.
Including it is important so it does not overwrite the text already written.
(7.) Append some text to the file.
(8.) Close the file.
Now onto reading the file...
(9.) Create a string variable that will be used to read the file.
(10.) Create an object of the ifstream class
(11.) Use the object to open the file with the member function open.
We must include ios::in as the mode parameter.
With this approach, the mode parameter is required.
(12.) Error Handling: Prevent file system error in accessing the file and/or reading it.
Write a conditional statement that will read the file if the file is accessible and open, then close it; or
display a message if the file is inaccessible and/or not open.
In other words:
If the file is open and accessible, read the file and close the file.
If the file is not open and/or not accessible, display a message that the file is not accessible.
Please review the screenshot and the comments.
Please submit clear screenshots of your program (all codes and the output).
For any question from the textbook, please include a clear screenshot of the question number and the
question.
DB Requirement Number (3.) is required.
In other words, you may not implement any method already implemented by any of your colleagues.
(1.) Use any academic field/discipline/area of your interest.
Find any topic(s) in that discipline that you are knowledgeable about/proficient in.
With clear explanations and comments, write programs that:
(a.) Writes text to a text file
(b.) Appends text to the text file
(c.) Reads from the text file.
Use any approach you prefer.
Cite your source(s) accordingly.
(2.) Question $(1.)$ on Page $181$ of your textbook.
(3.) Question $(5.)$ on Pages $183$ and $184$ of your textbook.
Please interact with your colleagues.
Let your colleague learn something new about his/her post based on your response.
Your response should improve the post of your colleague.
(1.) Use any other function to achieve the same output.
Submit clear screenshots of your program (all codes and the output).
(2.) If your colleague attempted Question (1.); use any function that you learned in any of the classes to work
on the same file used by your colleague.
Submit clear screenshots of your program (all codes and the output).
Please submit clear screenshots of your program (all codes and the output).
For any question from the textbook, please include a clear screenshot of the question number and the
question.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.)
(2.) Please review the screenshots in Example $4$
Use the same file name.
The same output is required.
The spacing and format of that output is required.
There are three columns after the first line sentence as well as three columns after the
second line sentence in that output: the first column is for the Mnemonic, the second column is for the
and the Element, and the third column is for the Symbol.
Write a file that has only the sentences, the mnemonic, and the elements without the symbols.
Insert each symbol to the corresponding element in each line.
Include clear explanations as comments in your program regarding the method(s) that you used to do it.
Read the file.
(3.)
Microsoft Foundation Class library, desktop application,
Students will:
(1.) Discuss the Microsoft Foundation Class library.
(2.) Develop a C++ desktop application using the Microsoft Foundation Class library.
(1.) Textbook Chapter
(2.) MFC Desktop Applications
(www.docs.microsoft.com/en-us/cpp/mfc/mfc-desktop-applications?view=msvc-160)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(3.) Type Microsoft Foundation Class or MFC in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(4.) Type Microsoft Foundation Class or MFC in the search bar and view/read the results.
Due to time constraints in doing the videos (I prefer to do videos because it deals with desktop apps) for
this lesson.
You do not need to respond to the initial post of another student.
However, DB Requirement Number (3.) is required.
In other words, no two students should write the same thing (any of the sentences).
By now, you have reviewed videos and/or notes on the Microsoft Foundation Class in the
LinkedIn Learning (Kent State University) and/or O'Reilly Online Learning learning platforms.
(1.)
(I.) Using five sentences, please write a summary of what you learned. Number your sentences.
(II.) Cite your source(s) accordingly.
Students will:
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(2.) Type Unified Modeling Language or UML in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the O'Reilly Online Learning link
Follow the directions to access the website.
(3.) Type Unified Modeling Language or UML in the search bar and view/read the results.
There are four options for your Final Exam.
Please choose only one option.
This option is based on your textbook (MindTap course).
This implies that it is not free.
However, you have two-weeks free access.
So, it is free if you can complete all the graded assessments in two weeks.
Please click the Gradebook and complete all the assessments there.
The assessments that are automatically graded count for the Final Exam.
The assessments that are to be manually graded count for the Final Project.
Access the MindTap Course
Course Key: MTPQ5FCQWR2M
This exam is designed to assess your understanding of the advanced C# concepts.
You have reviewed several topics and several concepts in each topic for eight modules.
Pick at least $1$ concept in at least $1$ topic in each of the $8$ modules.
That gives at least $8$ concepts in $8$ different topics in $8$ modules.
Find two more concepts in any topic in any module.
That gives $10$ concepts.
For each concept, please:
(1.) Write at least three sentences about that concept.
(2.) Develop a program about that concept.
In other words, write at least one code example about the concept.
Run the code.
Display the output.
Submit clear screenshots of your program (code and output)
Deliverables:
(1.) $10$ concepts in $10$ different topics for $8$ modules
Please write the: Module number, the Topic, and the Concept
(2.) Three sentences for each concept.
(3.) Code for each concept.
(4.) Output for each concept.
Please submit all these information as a zipped folder (.zip only) in the Final Exam folder of the Blackboard course.
There are three options for your Final Project.
Please choose only one option.
It is important you communicate with me for approval prior to doing this project.
Because the course deals with only desktop applications and console applications,
(rather than web applications and mobile applications), you may not do any project that requires a web server
such as contact forms and registration forms among others.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Think about any of these companies: our Institution: Kent State University; your local campus; your work place; public and
private schools (excluding home schools); organizations, firms, and businesses
(excluding controversial firms and the like).
Any company you choose should have a verifiable website.
The direct link of the company's website is required.
(2.) Identify a problem on the website that you want to solve.
The problem must be solved by programming using the knowledge acquired from any of the course
topics/concepts/description/learning objectives.
Think about your Midterm Project. You solved a problem: calculating bills, federal taxes, etc.
(3.) Develop the computer program to solve the problem.
Test the program to ensure that it works.
Write detailed comments as applicable.
(4.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What problem did you identify?
Did you solve the entire problem or part of the problem?
What course topics/concepts/description/learning objectives did you apply in solving the problem?
How did you solve the problem?
Did you encounter any issues while trying to solve the problem?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Program (all files)
(2.) Clear screenshots of your program (code and output)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
The final project is designed to assess your understanding and analysis of data using the knowledge you have
acquired in the course.
Please:
(1.) Visit my website on: Descriptive Statistics
(2.) Review the information for a good understanding of Descriptive Statistics.
It is highly likely that you have a prior knowledge of this topic. Is that right?
(3.) Click the Project link.
(4.) Review the Project Examples. Ensure you follow all the instructions and directions.
(5.) Complete the Final Project for your course.
(6.) Ask questions. I can help.
If you have any issue at any time and you have reviewed the resources I provided and you cannot fix the issue,
please attend the Office Hours/Live Sessions so I can help you.
(7.) Include all these: (documentation of all your Math work and the .exe file) in OneDrive, create a
shareable link, and post the link in the Final Project Drafts forum of the course on Blackboard or send to me via email.
You may also upload them directly if you prefer.
I shall review and provide feedback.
(8.) When you are done with your project:
Make sure your executable file runs by itself outside the project folder
If it does run, include these three items: single executable file (that runs by itself outside the folder), the
Math documentation (Word document that has the Math part), and the entire project folder, into a folder,
zip the folder (.zip extension only) and submit it in the appropriate area of the Blackboard course.
If it does not run, please fix it.
If you cannot fix it, please attend the Office Hours/Live Sessions so I can help you.
NOTE: Any actual project submitted to me via email will not be graded.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Your Midterm Project is a Console Application.
If you did your midterm project very well and you want to develop a C++ desktop application for the same
application, please go ahead.
Test the program to ensure that it works.
Write detailed comments as applicable.
(2.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What did you do?
Did you encounter any issues?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Executable file.
(2.) Program folder (all folders and files)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zip file (.zip only) in the Final Project folder of the Blackboard course.
NOTE: Any actual project submitted to me via email will not be graded.
Dear Students,
Greetings to you.
As you evaluate me and my teaching style on the Blackboard course, I ask that you consider these questions
in addition to the survey questions.
Thank you for giving me the opportunity to teach the course.
It was nice working with you.
I wish you the best in your academic profession.
Thank you!
Samuel Dominic Chukwuemeka (SamDom For Peace)
B.Eng., A.A.T, M.Ed., M.S
Working together for success
Classroom/Learning Environment: Blackboard course management system.
Course Assessments: Discussion Board (DB) assignments, Midterm Project, Final Project and the Final Exam
Direct forms of communication: live office hours/tutoring sessions, emails, comments to your DB posts and responses and
phone calls.
Indirect forms of communication: course announcements, websites (notes, videos, etc).
Course Contents
Please review the Course Description and Student Learning Outcomes
It is the first link in your course.
Those are the basic topics that KSU require that I teach.
(1.) Did I cover those topics: teaching and/or providing resources for those topics?
(2.) Did I cover other necessary topics that is relevant for you to succeed in your profession?
(3.) Did the assessments demonstrate the application of the topics?
(4.) Did the contents and assessments demonstrate important skills such as critical thinking, use of technology,
creativity, and organization among others?
Teaching and Learning
(5.) Did you acquire any knowledge from me?
(6.) Did you acquire sufficient knowledge, or more than sufficient knowledge from me?
(7.) Did you acquire any knowledge from any of your colleagues because of how the course was set up?
(8.) Did you acquire sufficient knowledge, or more than sufficient knowledge from any of your colleagues because of
the way the course was set up?
(9.) Did I provide multiple ways of completing each assessment?
In other words, were you given several options of completing each assessment?
(10.) Did I provide effective feedback for any of your assessments?
(11.) Did you acquire any knowledge based on that feedback?
(12.) Did the feedback help you improve in any way?
(13.) Did you have enough support to ensure the successful completion of the course?
Were your questions answered?
Did you have enough resources/learning aids?
(14.) Did I provide a safe and conducive environment for learning?
(15.) Was the Grading Method fair?
Pacing Guide
(16.) Were you given enough time to learn the contents?
(17.) Were you given enough time to complete the assessments?
Consider the fact that you were given two due dates for your Midterm Project, Final Project, and Final Exam; and that there
was no penalty for late work after the first due date.
Professionalism
(18.) In all our communication (both direct and indirect), did I act professionally?
(19.) In all our communication (both direct and indirect), did I use a respectful tone?
(20.) What do you like or dislike about our communication?
Personality
(21.) Based on your experience with me (taking the course with me and communicating with me among others), how
would you describe my person?
Do I give a lot of work?
Do I give a lot of explanations?
Do I have a lot of expectations for my students?
Do I really want you to learn?
Do I really want you to succeed?
Do I ask a lot of questions?
Do I answer questions with questions sometimes?
In those times, please note that it is a teaching technique.
It is never meant to disrespect you. I do not disrespect my students. I respect them.
It is a technique to guide you to review directions/concepts, and explain what you do not understand.
Would you take another course with me? Why or why not?
Did your views/perception about me affect you in completing this course successfully or unsuccessfully?
Need a programmer for personal/professional/commercial projects?
Look no further. Any of my available students (not just the ones listed here) can help.
Just head on to the Division of Student Affairs, Kent State University
or contact me here or via my school email address.
These are nice real-world projects done by my students.
Some of them are Midterm Projects while some are Final Projects.
Because of FERPA (Federal Educational Rights and Privacy Act) laws, only the first names of my students are
written.
(1.)
Georgia Public Service Commission: Winter Rate (October - May)
by Ryan
As at today: 12/30/2021, the verifiable website for this application is:
Georgia Power Bill Calculator: Winter Rate (October - May)
(http://www.psc.state.ga.us/calc/electric/GPcalc.asp)
(2.) GPA Calculator for Trumbull Career & Technical Center students (can also be used by any student using U.S grading scale) by Ty
As at today: $12/03/2020$, the verifiable website for this application is: Trumbull Career & Technical Center
(http://www.tctchome.com/)
(3.) $2020-2021$ Federal Tax: Single Filing Option by Brennem
As at today: $12/03/2020$, the verifiable website for this application is: IRS.com (This is not IRS.gov)
(https://www.irs.com/articles/2020-federal-tax-rates-brackets-standard-deductions/)
Summer (June-Sept) Base Charge: $14.50 First 1000 kWH: $0.100511 Over 1000 kWH: $0.10304Alabama Power increased their rates
C++ Standard Library:
Tutorials (Free)
C++ Tutorial: W3schools.com
(Free)
C++ Documentation:
Microsoft (Free)
C++ Developer Community
C++
Developer Community (Visual Studio)
American Standard
Code for Information Exchange (ASCII) Characters
Sorting
Techniques and Algorithms
LinkedIn Learning (Kent State
University)
O'Reilly Online Learning
For Kent State University students, Select your Institution > Choose “Not Listed?
Click here.”
Enter your Kent State University email address and click Let’s Go
C++ Institute: C++
Certification Exams - ITExams (Free Past Questions and Answers But Requires Patience)
Tutorials, Exercises, and Solutions from W3Resource (Free)
C++ Programming Exercises and Solutions from W3Resource (Free)
SoloLearn (Free)
C++ for
Programmers - Udacity (Free)
C++ Notes for Professionals: Stack Overflow Documentation (Free)
Wikibooks: C++
Programming (Free)
Stack Overflow: Question and Answer Forum
for Computer Science
Open Education & Development
Group (Free Course; Not Free Exam)
Lynda.com from LinkedIn Learning (Start for
Free. Then,
not free)
Codecademy (Start for Free. Then, not
free)
Chukwuemeka, S.D (2016, April 30). Samuel Chukwuemeka Tutorials - Math, Science, and
Technology.
Retrieved from https://www.samuelchukwuemeka.com
Malik, D. S. (2018). C++ Programming: From Problem Analysis to Program Design. Cengage Learning.
corob-msft. (n.d.). Microsoft C/C++ Documentation. Docs.Microsoft.Com. Retrieved June 30, 2020,
from https://docs.microsoft.com/en-us/cpp/?view=vs-2019
Free C++ Programming Book. (n.d.). Books.Goalkicker.Com. Retrieved June 30, 2020, from
https://books.goalkicker.com/CPlusPlusBook/