BU 2010 Business
Programming
with Visualization
Dr. Ebrahimi
H208 Campus Center
Mon-Thurs 11:45am - 2:15pm
Textbook:
C++ Programming Easy Ways
Volume 1 & 2
Week 1 (May 29-May 31) - Ch 1-2
Welcome to Business Programming with Visualization and I am your Professor : Dr. A. Ebrahimi and this is my website you will find always something interesting.

I know that you are anxious to know what programming is, write your first program. Before hand we need to familiarize ourselves with some background concept. While it might boaring and time consuming but the learning is worthwhile since it will give answer some of your questions as we cruse through the course.
Please read Chapter 1 as how programming and languages has evolved by itself and changed our life. The concept of object oriented programming and procedural programming will be done in parallel. We are examining a system known as WPOL (Web Plan Object Language) which is plan oriented and provides unlearned material to students as they learn new subjects. Sample Link
| WPOL |
Student Average Plan |
|
Observation (Phase 1) |
Beginner (Level 1) | ||||||||||
![]() |
|
|||||||||||||
|
Student Average Plan |
||||||||||||||
| Plan Description: | Compute the average of a student's assignment, midterm, and final scores. A student's id, assignment, midterm, and final scores will be input. The student's id, along with the computed average, will be displayed. | |||||||||||||
|
|
||||||||||||||
|
|
|
|
|
|||||||||||
|
|
|
|||||||||||||
|
|
||||||||||||||
| Build Plan | ||||||||||||||
The first assignment is to build a simple student system that will be done phase by phase throughout the course.
Phase 1 will be to compute the average scores for students given assignment score, midterm score, and final score. Students are identified by their id. (Ch 1-2)
What is the plan? Student Average
What is the input plan? Student Input Plan (id, assignment, midterm, final)
What is the process plan? Compute Student Average
add the scores together and divide the sum by 3
What is the output plan? Display Student Average
Input - Student id, assignment score, midterm score, final score
Process - Compute the average
Output - Student id and average
The programming language of
the course is known as C/C++ which
is
the foundation for many other languages such as Java.
THE EVOLUTION OF COMPUTER PROGRAMMING AND LANGUAGES: AN OVERVIEW OF C AND C++
It is important to familiarize yourself with the fundamentals of computer programming, computer languages, and their evolution. It may not be apparent to you at this time how this knowledge is going to help you to program in C/C++. It should, however, be noted that within the past fifty years, a multitude of programming concepts and methods has been introduced, and many different languages have been designed. Yet, they all still depend on a foundation that has remained relatively the same.
In this chapter, you are going to encounter unfamiliar terminology. What I would like you to do is to skim through this chapter and grasp as much as you can, without attempting to understand everything fully. By examining the history of computer programming, it is hoped that you will be able to better understand the way programming and languages are shaped, and have an idea as to what to expect for the future of computer programming and languages.
In order to give you a picture of computer programming and its abilities, I will introduce you to a very important program that is known as a search, written in both C and C++. You will then experience what I call the magic of programming, where the knowledge of building one program will lead you to build other programs without much effort. For example, you will see how a Telephone Operator Search Program can also act as a language translator, a dictionary, and can also easily become a bank or supermarket retrieval system.
I will conclude the chapter by giving examples of pitfalls in C/C++ programming that may cause misconceptions and delay learning. These pitfalls, which are the result of hidden notions and unknown rules, are contributing factors to what I call the mystery of C/C++ programming. You should be aware that the problems these pitfalls cause have nothing to do with your intelligence, and that you will learn to solve them.
By going through the foundations of programming and languages you will find it easier to build programs from scratch using C/C++ in the chapters that follow.
WHY PROGRAM?
Historically, the sole purpose of computers was to serve the scientific communities. Later on, computers progressed rapidly into business and education. Now, they are around us everywhere, and there is hardly an industry that does not need them. Whether in business or in the home, computers have come to maintain a dominant role in many people’s lives. What was once done manually, mechanically or electrically has been replaced, or will be replaced, with computers.
Although computers play a critical role in our society, most people are unaware that a set of instructions, known as a “program”, governs and operates the computers. A computer demonstrates its intelligence through the execution of a program, and without programs a computer is just a useless box. A computer becomes friendlier, easier to use, and more efficient in direct proportion to the quality of the programs it runs. Programs can be regarded as the “mind” of the computer, and without them a computer cannot function. Programs can be created, modified, expanded, enhanced, and/or customized to one's needs. You might want to know what a program is and what it looks like even before you learn how to program.
Let’s first discuss what a computer is. A computer can be considered a machine with three main components: 1) a central processing unit (CPU), where the activities are initiated, coordinated, and performed; 2) memory, where information (program and data) is stored and retrieved; and 3) input and output devices, where information is entered and displayed. The CPU and the memory perform together, just like the cerebral cortex of our brains, while the input/output devices are analogous to our sensory organs. When the three components work together, a task is initiated, retrieved, analyzed, performed, ultimately stored, and/or displayed.
I cannot emphasize enough how important it is to learn programming, but I would also like to point out that teaching and learning programming is still considered a difficult task for many people. At least there is no discrimination when it comes to learning programming for it can be done literally at any age, almost as soon as you are able to read.
ARE WE PROGRAMMED?
For a moment, let’s put computer programming aside and think about ourselves. After all, aren't we all programmed genetically, psychologically, and socially? Don't we follow a set of instructions that consist of a sequence of events, then making decisions, and repeating this process over and over again? These sets of instructions are known as programs, which can be presented by a natural language, such as English. What is your program today? Can you identify a sequence of events? Did you make any decisions? Did you repeat any event, or will you repeat the same set of events tomorrow?
IS EVERYTHING PROGRAMMED?
Before you begin to learn how to program, it is important for you to know that the internal hardware (chips) of the computer is programmed. When you turn on the computer, the environment and interface is programmed. Examples of the user interface and operating systems are DOS, Windows, and Unix. In addition, C/C++, the programming language that you are going to use, is already programmed. Moreover, games, word processors, ATM machines, communication systems, movie special effects, and almost all things else are programmed. Now it is your turn to program, from business applications to game design and hardware controls.
COMPUTER PROGRAMS AS PRE-AGREED RULES
Try to imagine the old days, when cavemen had to communicate with each other without any sophisticated language skills. Whether they communicated through sound or signs, they had to come to some kind of agreement and understanding amongst themselves.
Suppose you want to communicate with a partner not with sound or signs, but by turning a series of light bulbs on and off according to the following rule:
|
Let there be eight light bulbs situated on a desk, and let any communication between the two of you be achieved by turning these bulbs on or off at a given time. |
How could effective communication be achieved? There would have to be some sort of pre-existing agreement about how any eight possible combinations of lights switched on and off could represent the alphabet, numbers, special signs, words, or actions. For example, you may agree that when the first two light bulbs and the last light bulb are on it will represent the letter A. Similarly you may agree to represent the letter B with some other combination of on and off. This trend can go on to represent other letters, digits, and special signs.
To make it simple, we are going to show lights on as 1 and lights off as 0. We will call each light a bit. 1 will represent a lit bulb, and 0 will represent an unlit bulb. These 1s and 0s are referred to as binary numbers. For instance, the letter A is represented as an eight-bit combination of 11000001. The letter B is agreed upon as 11000010, and the number ‘0’ is 00110100. These eight-bit combinations are known as a byte. We have enough combinations of on and off (1's and 0's) to represent the entire alphabet, digits, and any other signs. Now that you know how to represent each digit and each letter with zeros and ones, you would be able to place each digit representation next to each other to form a number. It would be like placing each letter next to each other to form a word. Can you imagine how your name can be represented using this kind of agreement?
CHAPTER 2
INPUT, PROCESS, OUTPUT (IPO)
The computer is in a constant cycle of input, process, and output. The computer waits for you to enter the required information (input). Based on the entered information, the computer takes the appropriate actions (process). Finally, the result is displayed on the screen or printed out (output). An analogy for input, process and output would be a food processor where food, fruit and other ingredients are put into the machine. Afterward, based on the selected setting, such as cutting, chopping, or mixing, the food processor performs the appropriate task, and finally the desired mixture is ready to be used.
By the end of this week, you should be able to write a program, compile, and run it with input and output.
How do you write a program? You need to have a compiler for C++ to work with.
If the computer lab we are using Microsoft Visual Studio .Net. However
there are several aother compiler that are free of charge and easy to work such
as Dev C++ (www.bloodshed.net). To
install the software go the site and download the compiler.
In you are doing it with MS Visual Studio (there is also a free version available http://msdn.microsoft.com/vstudio/express/visualc/) you must follow (select Visual C++ projects=>win32 project=> give a name=>application setting=>empty project=>finish
Go to source file and right mouse=>add new items=>select C++ file and give a name and type the program.
We are going to write a program which is on the page 45 and test it with the compiler. This program will compute the gross pay and netpay for an employee. The input for this program is employee id, hours worked, hourly rate, and tax rate (as a constant) At the same time think of how you can transfer this program to your assignment
The plan after inputting the variables (employeeid, hoursworked, hourlyrate, and taxrate) is to compute grosspay by multiplying hoursworked by hourlyrate. The next plan would be to find the taxamount by multiplying the grosspay by the taxrate. The final plan would be to find netpay which would be done by subtracting the taxamount plan from the grosspay plan.
Let us the convert the above plan to a C++ language plan. First we need to go to the compiler and type all the names that we will be using in the program. What are they? Employeeid, hoursworked, hourlyrate, and grosspay for now. We'll do the rest of the variables later.




At this moment, after you went through this hectic process of visual studio type the following skeleton including the variable names of your grosspay program. From the "Build" menu select the "compile" option. You might get some errors. Remembers errors are good at this time of learning.

However we can run the above program to find out what would happen. Nothing would happen since there is no interaction for input and no output to display.
This is a sample grosspay program:

Your first assignment (student average) would be like above program.
What would be the plan to change (convert) this program to student average plan
Week 2 (June 4-June 7) - Ch 3-4
Phase 2 - Repeat the student average program for 5 students, as many students as entered, and end of file.
Phase 3 - (Beg.) Assign a message: pass or fail. (Int.) Assign a range of excellent, good, satisfactory, passing, failing. (Adv.) Assign a letter grade based on the student average.
Innovation: Give a choice to add extra credit.
Would you be able to apply this example to weather forecasting.
Decision Making: making programs intelligent
Have you heard of computers that beat chess champions or mimic experts? The decision making statement responsible for making a program an intelligent entity is known as the "if" statement. However, not using the proper decision-making can cause a program to fail or possibly become dumb. This is known as a computer error. An example of a program error is to print or display a paycheck for an employee who worked regular hours with a negative amount of money.
If given an employee's salary, how would you determine the tax rate? If given the number of hours an employee worked, how would you determine the overtime hours? If you were asked whether you want to continue, or to stop what you were doing, what would you answer? If you were asked to enter your password and you typed either the right or the wrong password, what would you expect to happen? If given a menu with a list of items, how would you make a selection? These are a few examples of decision-making. They are used in a similar fashion in programming.
WHAT IS AN ALGORITHM? WHERE DOES THE ALGORITHM COME FROM?
When it comes to programming and problem solving, the word “algorithm” is frequently used. At first glance, most people associate the word algorithm with a mathematical term such as Logarithm. In programming, algorithm refers to the problem solving steps that are needed to find a solution to a problem, such as finding the shortest path from one city to another or computing employee wages. Where does the word algorithm come from? It came from the Persian scientist Alkharazmi who wrote a book around 825 A.D. called “Algebr and Moghabeleh” which translates to “Reduction and Calculation”.
2A) you are going to loop the student average plan program for 5 times.
You need to set a counter variable and use that counter variable to loop five times. At this moment use while construct as shown below
while (....<..){ ....;...; }
2B) Program ask user to enter the number of loop (e.g.cout <<"Enter the number of students:"); cin>>n; while (.....<n){ }).
3C) The data for each student has been already typed in a row separated by a space in a file which is known as input file by given a name. The program will access the data file each time and calculate the average for each student until the end of file has been reached. This is an amazing program and you should be very happy by learning and applying it.
Hints for phase 2 assignments: Phase 2 has three part and all deals with the loop.
#include <fstream>
using namspace std;
ifstream fin ("student.txt");
while (fin>>id>>..........){
......
}


Payroll Program using a file




A major error in C++ is to use the "=" sign twice to make it "==" if not you receive this error :

It assigns marital status to be "S" only which is single regardless of what you assign the marital status in the employee file

Its supposed to be like this :

The output is supposed to look like this :



Wednesday June 20
In order to work with a data file (end of file) in your C++ program you need the following three steps:
1) Include the fstream on top of your program. The keyword fstream stand for file stream. This is done next to the line that has iostream
#inlcude <fstream>
2) Associate the data file name to a stream name such such fin (file in- input from file). You are going to use fin instead of cin (console in- keyboard) your program.
ifstream fin ("student.in");
the file student.in has been created by notepad. make sure note pad does not save it as .txt but .in.
3) use the fin inside the while loop. This will access the data as well as terminate the loop when there is no more data (end of file has been reached.
while (fin>>stdid>>assignmentscore>>midtermscore>>final score){
}
3) Use the