Spring 2008  BU4040

Home  |  Syllabus  |  Journal  | Project ExamResearch  |  Gallery

 

 

 

What is a program? A program is a set of instructions telling the computer what to do. 

 

Required Text:

C++ Programming Easy Ways -Dr. Alireza Ebrahimi

 

 

First Assignment:

1. Pick a program from chapters 1-20 in the book. Be unique,

extreme, anything you want to be!!!

 

2. Write the program. Type the program.

Where?: Word, Notepad (preferred), or any text editor. Save the program.

 

3. Compile it. What is there to compile and how to you compile?

The program that you just typed. What is a compiler? Compiler is

a translator. A translator is someone (program [software]) that

translates one language to another language. Translate the source

language to the target language. The target language is the

machine. What is the source language? The source language here in this class is C++ and it is a very powerful and important language. The definition of compiler is to convert or translate your C++ to assembly (machine) language.

 

4. Therefore to compile you need a compiler. The compiler you will need is the C++ compiler, either Microsoft Visual Studio C++ or Dev C++. Both of these compilers their own editors and more!

 

5. Run it or execute it. You may need resources.

[Angie picked the program on page 113. The program deals with gross pay, overtime, and Y2K problem. Years back companies spent 3trillion dollars on programming.]

 

 

________________________________________________________________________________________________________

 

Tuesday Jan 29 2007

LAST CLASS REVIEW:

- The first assignment was to A) pick a program in the textbook chapters  

  1-20.

  B) Write or type the program using an editor (ex. Notepad , Word, etc.)

  Notepad is because it is a text editor by nature.

  C) Compile it (the program). Compiler translates the source to the target.

  For example C++ converts program to assembly language. All you need

  to work with  C++ is a compiler. If you have a warning you can still 

  execute

  D) RUN or EXECUTE the program. Take the action to activate it.

  E) To submit your work use CONTROL & PRINT SCREEN

 

 

 

 

QUESTIONS:

 

_________________________________________________________________________________________________

 

Jan 31, 2008

#include<iostream>

using namespace std;

swap(int slot[],int i,int j){

int temp;

temp=slot[i];

slot[i]=slot[j];

slot[j]=temp;

return 0;

}//SWAP

main(){

int scan,pass,n=10,i;

int slot[]={8,3,1,5,7,10,4,9,6,2};

for(pass=1;pass<n;pass++){

for(scan=0;scan<n-pass;scan++){

if(slot[scan]>slot[scan+1])

swap(slot,scan,scan+1);

}//end scan

}//end pass

cout<<"SORTED ITEMS:" <<endl;

for(i=0;i<n;i++)

cout<<slot[i]<<" ";

cin.get();

cout<<endl;

return 0;

}//MAIN

 

** If you have never seen a compiler here is DEV C++ :

 

 

    The program above sorts numbers. The program looks like gibberish.

 

The steps he took to do the program

  1. Typed the program looking in the book.

  2. Then go to DEV C++ Compiler and Download it. (It takes less than 5minutes)

  3. Then activate Dev C++

  4. Type the program from page 353 (because he liked the challenge).

  5. Saved it on the compiler as exchangesort.cpp

  6. Compile it, there is an icon on the top to compile your program.

  7. He had about 3 or 4 compiler errors. The messages were not to the point.

  8. He then fixed his errors. To check make sure your program is EXACT as the one from the book.

  9. Run the program. (To hold the output screen use statement cin.get() or system ("pause")

** According to C++ by Default ( Automatic) functions are int.

*** The new version of C++  treat the function differently.

 

 

_______________________________________________________________________________

February 5, 2008

 

 1. Review of last class

    a] Do you know how to install the compiler or work the    

        compiler in the Lab.

    b] You should have the first assignment done.

 2. Chapter 2 reading from the book

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.

 

THE MAIN SKELETON OF THE C AND C++ PROGRAM

 

A C/C++ program has a main skeleton, regardless of how large or small it is. Every program starts with the word main, followed by an open parenthesis and closed parenthesis. The beginning of the program is marked with an open brace, and the end of the program is marked with a closed brace. Let me show you the simplest program one can create in both C and C++.

 

Text Box:           
main( ){           
 
            // Body of main…
 
}//MAIN

  

 

 

 

   Text Box: Figure 2.1 – main( ) function of C/C++ program

 
 

The fact remains that this program does not perform any task, and its sole purpose is to illustrate the main skeleton of every program. The word main in the program signifies that this is the main program (main function) where the main activities occur.  There are sub-programs (functions) that originate (called) from the main program. After the word main, you observed an open parenthesis immediately followed by a closed parenthesis and nothing in between. The opening and closing braces indicates a block where the program statements will be written in between.

// means comment. You should always include your name in the program.

It is not for the computer, it is for you and others. For example for the professor to know what you are doing. 

At this moment there are words, symbols that you do not know what they are. It will take time to explain the meaning. For now just accept this notion because they will be explained at a later time.

                In class Fig. 2.1 test, 2.3b

Today we learned how to run a program that does nothing. By Justin

 

3. New assignment:

        Assignments are found at the end of each chapter.   

CASE STUDY – PAYROLL SYSTEM PHASE 2: INPUT/OUTPUT

 2A) Compute gross pay for each employee by interactively entering hours worked and hourly rate.

 The following is the sample input and output for Phase 2A:

                                                                                         // Your  INPUT should look like this

            ENTER EMPLOYEE ID: 5678

            ENTER HOURS WORKED: 40

            ENTER HOURLY RATE: 15.00

                                                                                               // Your OUTPUT should look like this

            YOUR ID IS: 5678

            YOUR HOURS WORKED IS: 40

            YOUR HOURLY RATE IS: $15.00

            YOUR GROSS PAY IS: $600.00

 

2B) Compute net pay for each employee by applying a fixed tax rate of 10%. You must enter each employee’s id. (Enter only last four digits of SSN at this time.)

 

Sample input and output for Phase 2B:

 

            ENTER EMPLOYEE ID: 5678

            ENTER HOURS WORKED: 40

            ENTER HOURLY RATE: 15.00

                       

            YOUR ID IS: 5678

            YOUR HOURS WORKED IS: 40

            YOUR HOURLY RATE IS: $15.00

            YOUR GROSS PAY IS: $600.00

            YOUR TAX RATE IS: 0.10

YOUR TAX AMOUNT IS: $60.00

            YOUR NET PAY IS: $540.00

 

 4. Presentation by your classmate Aletha

    * The purpose is to become comfortable with the    

       compiler. For example Dev C++

     What does this program do? Compute Gross Pay and Net Pay

     SYNTAX ERROR: No name should have a space in between.

-By default the main is an int.

PRESENTATION NUMBER 2

by; Farzad  page number 114

5. Building the class web management

 

_____________________________________________________________________________________________________

  

February 7, 2008

 

    PROGRAMMING IS A VERY CHAIN MATERIAL.

 You need to be able to understand each part before you can continue. My suggestion is to not miss any classes. If for any reason you miss a class please consult with someone about what was covered during the previous class that you missed.

 

 

These are the problems that some students have come across while doing the assignments:

Angie is demonstrating her code in regular c, she gets 5 points

 

Matt got a point

 

Jake gets a point because he sad C came before C++

 

Every time you see cout it means you're giving it away

 

cin = Console Input

cout = Console Output

keyboards use to be called console

 

 

What page in the text talks about the skeleton of C++?

Page 27

 

What words must be in a C++ Program?

main,

 

Programming was there to solve mathematical problems

 

If you have warnings you can still run it.

Birds can't fly without wings!!!

People can't walk without legs!!!

That is why people are fast.

 

_______________________________________________________________________

February 12, 2007

 

When working on assignments  try to understand what we need.

 

Jake demonstrated his assignment.

From page 65.

The program that Jake is demonstrating will loop 10 times. We know this because the count number is 10. How could we make the program loop one thousand times? Change the count number to 1000.

 

Jake's assignment had a warning because of the .h

 

 

Could you bike for me?

 

Infinite loop ^ 

 

 

Jeffrey &  Christina demoed their program from page 383.

    One way to know what a program does is to look at the input and the output.

 

 

Dr. Ebrahimi has created a program that you can never lose. You can have a tie but you would never have a loss.

** Computer becomes intelligent because of program. It can also become  stupid because of programs.

 

Default: When you said it, it is therefore established. Certain things you do not see is defaulted.

 

Chapter 2 talks about input and process (computation).

 

Emile demonstrated his program.

He did have a few errors.

The words that are bolded are reserved (key) words.

Two types of errors. SYNTAX errors and Logical errors.

 

Matt demonstrated his program:

 This program is written in C. (scanf & printf)

 

 

Patrick demonstrated his program:

This program is out of a different book ( How to Program by H.M Deitel & P.J Deitel )

 

 

 

 

NEXT THURSDAY FEBRUARY 21st WE WILL HAVE A 100 QUESTION QUIZ

You can submit 10 questions.

Make sure the questions are:

 

You can email the questions to:

Dr. Ebrahimi ebrahimidr@gmail.com

Jeffrey ( Class Captain ) thewiz919@yahoo.com

Christina ( Class Captain ) morellchristina@gmail.com

 

______________________________________________________________________________________________________

FEBRUARY 14, 2008

HAPPY VALENTINE'S DAY EVERYONE!

Go to fullsize imageGo to fullsize imageGo to fullsize imageGo to fullsize image

 

 

JUST A REMINDER QUIZ 1 WILL BE ON FEBRUARY 21ST!

Make sure the questions are:

PLEASE EMAIL YOUR QUESTIONS TO EITHER :

Dr. Ebrahimi ebrahimidr@gmail.com

Jeffrey ( Class Captain ) thewiz919@yahoo.com

Christina ( Class Captain ) morellchristina@gmail.com

 

 

WHAT IS CHAPTER 3 ABOUT?

 

 

 

 

 

 

 

 

 

You should understand and have a little knowledge of programs.

WORDS OF ENCOURAGEMENT: GET INVOLVED!

 

Philosophy of C++:

The philosophy of truth. Everything is true except for zero. For example number 1 is true. Letter a is true.

 

 

Ariel demonstrated his program from page 118 first.

 

 

Tuesday February 19, 2008

Quiz has been postponed to TUESDAY February 26th, 2008
The quiz will be open book, open note, just no communication.

Make sure to email your 10 questions to:
Dr. Ebrahimi ebrahimidr@gmail.com

And send carbon copies of the questions to:
Jeffrey ( Class Captain ) thewiz919@yahoo.com
Christina ( Class Captain ) morellchristina@gmail.com

Questions are to be:
non trivial / non tricky
True / False questions
From Chapters 1-3 & whatever we have covered or learned in the class.

In class questions:
Page 20 :
4. A systematic way (step-by-step) to solve a problem is known as a
algorithm. [ True ] What is algorithm? A systematic way to solve a
problem.
Ebrahimi would like you to use this terminology in your everyday life.
Algorithms are not always accurate.
According to page 14 Algorithm can mean solution as well.
Abstract form is another term for algorithm.
Algorithms should not be off tangent.
Flow Chart is a kind of algorithm.
Meteorologist are sometimes incorrect because they do not have a
correct algorithm.
To solve a problem their might not be an answer.

Page 48:
14. counter = counter +1 is known as a const not an assignment
statement. [False]


Page 100 " 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 a Logarithm. In programming, algorithm refers to problem solving steps that are needed to find a solution to a problem, such as finding the shortest path from one city to another computing employee wages. Where does the word algorithm come from? It cam from the Persian Alkharazmi who worte a book around 825 A.D. called "Algebr and Moghabeleh" which translates to "Reduction and Calculation".
An example of solving problems is a rubixs cube.


You can argue algorithms.
What does algorithm optimization mean?


Do you know how to make a garden omelet?
Egg & Cheese [ Luis gave an incomplete suggestion. ]
Angie's Suggestion
1) Crack Eggs without the yolk into a Bowl
2) Add Cheese and any garden vegetable you would like
3) Take a frying pan and heat it on the stove with butter
4) Mix the eggs and vegetables
5) Add the mixture into the warm frying pan
6) Then you wait about 5 minutes until the mixture becomes a solid white color [ What happened to the salt and pepper? ]
7) Then fold it in half
8) Serve it on a platter
What is the algorithm for assignment 2A & 2B?


What is Justin's algorithm from here to your house?
Take the bus
Stop at the Hicksville Train Station
Train to Penn Station
Then go to Grand Central Station the Metro North White Plains
Then get a ride to his house
Why people want to make featherless chicken?

^POOR THING! =/
Economically it saves money !
http://www.nextnature.net/research/wp-content/uploads/2006/10/chicken3~.jpg


*Every user name must be declared!

WORD OF THE DAY:
DELIMITERS

DEMOS:

Ariel
Page 118


Dante Demo:
page 97
Error secondnumber does not require a space.

Andrew's Demo:
Page 42

____________________________________________________________________________________________________________
February 21, 2008

 

 

Please work on your case studies for chapter 2 :

 

CASE STUDY - PAYROLL SYSTEM PHASE 2: INPUT/OUTPUT

 

2A) Compute gross pay for each employee by interactively entering hours worked and hourly rate.

    The following is the sample input and output for Phase 2A:

       

        ENTER EMPLOYEE ID: 5678

        ENTER HOURS WORKED: 40

        ENTER HOURLY RATE: 15.00

 

        YOUR ID IS: 5678

        YOUR HOURS WORKED IS: 40

        YOUR HOURLY RATE IS: $15.00

        YOUR GROSS PAY IS $600.00

 

2B) Compute net pay for each employee by applying a fixed tax rate of 10%. You must enter each employee's id. (Enter only last four digits of SSN at this time.)

 

Sample input and output for Phase 2B.

       

        ENTER EMPLOYEE ID: 5678

        YOUR HOURS WORKED: 40

        ENTER HOURLY RATE: 15.00

 

        YOUR ID IS: 5678

        YOUR HOURS WORKED: 40

        YOUR HOURLY RATE IS: $15.00

        YOUR GROSS PAY IS: $600.00

        YOUR TAX RATE IS 0.10

        YOUR TAX AMOUNT IS: $60.00

        YOUR NET PAY IS: $540.00

 

SELF-TEST TRUE/FALSE CHAPTER 1: EVOLUTION OF PROGRAMMING

 

_1. C++ is the superset of C containing whatever C already has.

_2. Comment symbols // were introduced by C  and the symbols /* .... */

    were introduced by C++.

_3. C++ is known as a better C as well as C with object-orientated 

    programming.

_4. A systematic way (step-by-step) to solve a problem is known as

    algorithm.

_5. A program is a set of instructions that tells a computer what to do.

_6. Every character has its own ASCII code, such as 65 for uppercase A

    and 97 for a lowercase a.

_7. Computer languages are ambiguous and natural languages are not

    ambiguous.

_8. C++ was designed before ALGOL and FORTRAN.

_9. APL uses <- for assignment (e.g c<- a = b) instead of = or := as in other

    languages (e.g. c = a + b )

_10. C and C++ are user-friendly languages and were designed for teaching

    purposes.

_11. An integer value has its own range _ e.g -32768 to +32767). Therefore

    32767 +1 becomes -32768.

_12. In C++, == is used for equality comparison and single equal (=) is used

    for assignment.

_13. Every problem has only one algorithm to solve it.

_14. A compiler will not find a logical error, such as substituting addition

    for subtraction.

_15. In order to get an output from a program you must edit, compile, and

    execute the program.

_16. A data file (input file) is a program and can therefore be executed.

_17. A C++ program has a file extension .ccp and a data file usually has

    extension .cpp  or .txt

_18. Borland C++, GNU C++, and MS Visual C++ are all compilers from

    different companies.

_19. VOID

_20. Decision-making is also called a loop

_21. If you have warnings, you can still execute the program.

_22. Comments in a program are executed just as statements in the

    program.

_23. With // you can only have a single line of comments.

_24. B,C,C++ Visual Basic, Java, Perl, and C# are all programming

    languages.

_25. The binary state of a computer is represented as 0's  and 1's at the

    lowest level.

 

 

SELF-TEST TRUE / FALSE CHAPTER 2:  INPUT, PROCESS, OUTPUT (IPO)

 

__ 1. An identifier (name) can include an underscore but not a space (e.g. tax_rate).

__ 2. If you have <iostream> without .h then you must have std:: before cin and cout or using namespace.

__ 3. A variable name is a user name with memory storage and its value can change.

__4. Keywords and system words are also known as reserved words and cannot be used for other purposes.

__ 5. cout will take in an input and cin will display an output.

__ 6. Every C/C++ program must have main( ) {   }.

__ 7. There is no need to declare all the variables used in a C/C++ program.

__ 8. The job of a C++ compiler is to detect and report all syntax errors.

__ 9. A multiplication operator is shown as an x and division operator is shown as a  \.

__ 10. Every single line in C++ ends with a semicolon.

__ 11. C++ is not case sensitive; therefore TAXRATE and taxrate are the same.

__ 12. Reserved words (key words) can be used as user words.

__ 13. The reserved word const indicates that the value will not change.

__ 14. counter = counter + 1 is known as a const not an assignment statement.

__ 15. In the following declaration: INT hw, ID; there is a syntax error.

__ 16. Every program (function) must either have a return at the end or a void before the main.

__ 17. cout and cin belong to C and printf and scanf belong to C++.

__ 18. You do not need to include <iostream.h> for cin and cout.

__ 19. \n and endl can be used for input to insert a tab in a line.

__ 20. const float taxrate = 0.10 is the same as float taxrate = 0.10.

__ 21. Every name must be declared and have a value before it is output.

__ 22. There is a logical error in the following statement: netpay = grosspay + taxamount;

__ 23. There is a logical error in the following statements: cin>>hourlyrate; cout<<”Enter hourly rate”;

__ 24. The following are built-in functions in C++: sqrt( ), time( ), and rand( ). 

__ 25. The arithmetic operators: *, /, and % all have the same precedence which is higher than + and -.


 

SELF-TEST TRUE / FALSE CHAPTER 3: LOOP 

__ 1. In C++ the expression 2<3 always evaluates to true, and 0 is always false.

__ 2. The statement while (Ø) {  } in a program will loop forever.

__ 3. Reserved words while, for, and do while can be used to loop.

__ 4. The exclamation operator ( !  ), means not in a example such as !=.

__ 5. The assignment statement c = c +1 is same as c++ and c += 1.

__ 6. To loop five times we need:  int counter =0; while (counter >5){ counter

    ++;.                                   

__ 7.  ifstream fin(“filename.in”); will associate an output file instead of an input file.

__ 8. When using end of file it is necessary to stop the loop by a counter variable in a loop condition.

__ 9. To loop a program 5 times, you must write the program 5 times.

__ 10. To run a program with a large amount of data it is better to enter the data each time interactively.

__ 11. Every time you recompile a program you must also recompile its data file.

__ 12. A C++ compiler will convert a file.cpp to a file.exe. 

__ 13. If there are no errors detected by the compiler, the program output is correct. 

__ 14. Instead of  ;  in a statement you can put , (comma).

__ 15. There is a logical error in the following declaration: float id;

__ 16. The keywords: int, float, double, char, and bool are known as basic data types in C++.

__ 17. The statement: cin << “Hello”; is syntactically and logically correct.

__ 18. The following loop will repeat 3 times: c = Ø; do{ c = c + 1;cout << “Hello”; } while (c < 3);

__ 19. A dummy value that is used to stop a loop is known as a sentinel.

__ 20. Instead of <iostream.h> you can use <iostream> with using namespace std.

__ 21. The identifier: 1pay is a valid name (identifier) in C++.

__ 22. A loop can have one or more statements enclosed in braces, or a single statement without braces. 

__ 23. When the condition of a loop becomes false, the execution continues at the statement after the loop.

__ 24. The while loop is more compact than for loop, since it keeps the loop control statements together.

__ 25. The position of braces in a loop is very important and you can’t choose your own style.   

 

 Make sure to email your 10 questions to:
Dr. Ebrahimi ebrahimidr@gmail.com

And send carbon copies of the questions to:
Jeffrey ( Class Captain ) thewiz919@yahoo.com
Christina ( Class Captain ) morellchristina@gmail.com

Questions are to be:
non trivial / non tricky
True / False questions
From Chapters 1-3 & whatever we have covered or learned in the class.

 

February 28, 2008

 

TO TAKE THE TEST:

STEP 1:

Go to www.oldwestbury.edu

 

STEP 2: CLICK ON Online Courses

STEP

STEP 3:

CLICK ON ACCESS YOUR COURSE

 

STEP 4:

Then log in like you would into the school computers.

STEP 5:

Then go to Business Programming w. Visualization & Take the Quiz 

 

Do page 62 & Run it.

You get 6 points for this class assignment and

after that 3 points as is and 2 points for changing it.

 

 

__________________________________________________________________________________________________________________

March 4, 2008

 

Case Study

Page 89

 

The main purpose of this phase is to get accustomed to the repetition of a program using a loop and reading data interactively as well from an external file.

Hint: Use a while loop.

3A) Expand Payroll Program so that interactively repeats for 5 employees.

EXAMPLE:

            Enter Employee Id           6740

              Enter Hours Worked            40

              Enter Hourly Rate            $  10

             

              Employee Id is                 6740

              The Hours Worked are         40

              The Hourly Rate is           $  10

              The Gross Pay is              $400

              The Tax is                         0.30

              The Net Pay is                 $280

 

              Enter Employee Id           3578

              Enter Hours Worked            30

              Enter Hourly Rate                10

Employee Id is                               3578

……………….

 

3B) Expand Payroll program so that it repeats for 5 employees from an input file.

Data typed and saved under employee.in

#include <fstream.h> instead of <iostream.h>

Use ifstream fin(“employee.ub”);

Use the same while loop as 3A

 

 

3C) Expand Payroll program so that repeats for as many employees as are entered interactively.

No loop counter needed.

Cout <<”Enter employeeid”;

While(cin>>employeeid) {…

….

cout<<”Enter employeeid”;

} //end while loop

Having cin>> in loop enables user exit loop by pressing ctrl/z

 

 

3D) Expand Payroll program so that it repeats for as many employees in the input file.

Enter more than 5 employees in employee.in

While(fin>>employeeid){…your program…..}//end loop

Don’t use any interaction or loop counter.  

·       A, B, C, & D is basically the same with one line change.

·       To understand each part

o   A- loop 5 times interactively (type by hands)

o   B- loop 5 times from the data (input) file

o   C- loop as many from keyboard (ctrl z)

o   D- as many from data file

 

__________________________________________________________________________________________________________________

March 6,2008

 

-NEXT THURSDAY MARCH 13, 2008 MIDTERM

 

Working on Chapter 3:

o  [5 pts to run the file as it]

o  How many years you want? How much do you want to pay? He always left to go to another room. He did not have a program all he had a was calculator.

o  By making the condition false. The condition of the loop false.

o  Press CNTRL Z , it stops the program

________________________________________________________________________________________________________________________

 

 

March 11, 2008

Captains: Jeffery Prudhomme & Christina Morell

 

 

 

 

 

·        

_________________________________________________________________________________________________________________________

 

March 13, 2008

Captains: Jeffery Prudhomme & Christina Morell

 

 

 

MIDTERM TEST:

GO TO OLD WESTBURY ONLINE & SUBMIT EACH PROGRAM AS AN ATTACHMENT. For example it will be 2a.cpp with the running of input and output. You can use CNTRL + PRNT SCREEN to copy and paste it to the word document. Each program should be attached separately.

(If there is any problem with the online email your programs to ebrahimidr@gmail.com and make sure you speak to Dr. Ebrahimi before you leave.)

 

 

_________________________________________________________________________________

March 25, 2008

Captains: Jeffery Prudhomme & Christina Morell

 

Chapter 4: 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 wit ha negative amount of money.

 

MAKING THE DECISION:

 

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 stop what you are 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 few examples of decision-making. They are used in a similar fashion in programming.

 

HOW DO YOU MAKE A DECISION IN C/C++?

 

In C/C++, decision making is done by using an if or a switch statement. The if statement uses the form shown in Figure 4.1.

 

 

if( expression ){

                //Body of it ( Runs only when the if expression is true )

 

}//IF

else{

                //Body of it ( Runs only when the if expression is false )

 

}//ELSE

 

 

The expression after the if must evaluate to either true or false. If the expression evaluates to true, the "body of the if", which is the statement next to parentheses, will be executed. If the expression evaluates to false, the "body of the else" will be executed. IF the body of if or the body of else contain more than one statement, then braces { } should be used. It is good practice to always use braces.

 

if( grosspay>1000)

    taxrate = 0.20;

else

    taxrate = 0.10;

 

Assign taxrate the value of 0.20 if grosspay is greater than 1000 otherwise assign taxrate the value of 0.10.

 

 

if( hoursworked > 40)

    overtimehours= hoursworked -40;

else

    overtimehours=0.0;

 

Assign overtimehours the value of hoursworked - 40 hoursworked is greater than 40 otherwise the value of 0.0 to overtime hours.

 

if( candidateIntitial == 'H' )

        hc=hc+1;

else

        oc=oc+1;

 

If value of candidateInitial is equal to H then increment the counter named hc by the value of one (1) and assign the value back to hc. If the value of candidateInitial is anything other than H, then add one to the value of the counter named oc and assign the value back to oc.

 

WHAT DOES THE EXPRESSION "IF" CONSIST OF?

 

The expression if, compares two values using the comparison operators of Table 4.1 listed below.

 

 

 

The result of the expression can be either true or false. IN C/C++, anything besides zero considered to be true. Therefore, the number zero is false and any other number is true. The expression if can be made more complex when making several evaluations or even an assignment statement.

 

[*If  you know and understand leap year by next class Dr. Ebrahimi will give you a dollar*]

 

______________________________________________________________________________

March 27, 2008

Captains: Jeffery Prudhomme & Christina Morell

 

 

CASE STUDY- PAYROLL SYSTEM PHASE 4:DECISION-MAKING pg 136

 

At this phase of the payroll system, we are going to include the appropriate tax rate (variable) rather than a fixed tax rate of 10% (constant). The program will also compute the over time pay.

4A) Assign different tax rates based on the following gross pay:

            gross pay > 500.00 then taxrate = 0.30 (30%)

                      gross pay > 200.00 then taxrate = 0.20

                      anything less     then taxrate = 0.10

       

    HINTS FOR 4A starting on page 126, 134 (info statement line 14 to the end)

 

4B) Determine an additional tax rate based on marital status:

    1) Declare marital status as a number (integer).

            1=Single     2=Married     3=Head of Household

 

                            an additional 5% will be added to the tax rate of a single person

                            subtract 5% if head of household

     cin >> maritalstatus

     if (maritalstatus == 1)

     taxrate = taxrate + 0.05;

     else if (maritalstatus ==3)

     taxrate = taxrate - 0.05

                                          

    2) Declare marital status as character

         (working with either letters M, S, H or character digits 1,2,3)

    3) Program should accept either upper case or lower case letters for marital status

         ( e.g. accept M or m).

 

    HINTS FOR 4B is on page 117 or on page 132

  

 

4C) Compute the overtime pay according to the following formula:

        Any hours over 40 are considered time and a half ( overtime ).

        You may want to find over time hours ( e.g. hoursworked -40) and over time pay

        (e.g. overtimehours*hourlyrate*1.5).

 

 

________________________________________________________________________________________________________________________

 

April 8th

Captains: Christina Morell & Ariel Candelario

 

Work on Chapter 5

make sure to demo it, page 159

 

Start with line 1,3-12, 25-27, 32-33 you are obviously going to get errors. Do not forget to add system("pause"); When you save it call it 159a.cpp

 

include<iostream>

using namespace std;
main(){
char empid[ 100 ][ 12 ];
char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];
int hw[ 100 ];
double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ];

int counter = 0;
int i;
cout<<"ENTER EMP ID, FNAME, LNAME, HRS WORKED, HRLY RATE ctrl z to end"<<endl;
while( cin>>empid[counter]>>fname[counter]>>lastname[counter]>>hw[counter]>> hr[counter])
cout<<endl;
cout<<setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
<<"LAST NAME" <<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6)
}//FOR
system("pause");

return 0;
 

then add lines 29 & 30

 

#include<iostream.h>
#include <iomanip.h>
int main(){
char empid[ 100 ][ 12 ];
char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];
int hw[ 100 ];
double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ];
int counter = 0;
int i;
cout<<"ENTER EMP ID, FNAME, LNAME, HRS WORKED, HRLY RATE ctrl z to end"<<endl;
while( cin>>empid[counter]>>fname[counter]>>lastname[counter]>>hw[counter]>> hr[counter])
cout<<endl;
cout<<setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
<<"LAST NAME" <<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6);
cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]<<setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;
system ("pause");
return 0;
}//MAIN

 

________________________________________________________________________________________________________________________

April 10th

Captains: Christina Morell & Ariel Candelario

 

NEXT TUESDAY THERE WILL BE NOT LECTURE; CLASS WILL BE ONLINE!

 

PAGE 166

 

The purpose of this phase is to expand the payroll system to display all employee information in a tabular form by including arrays.

A) Display company title and a header that labels the output in a tabular form. Input the first name and last name of an employee.

 

char firstname[10], lastname[15];

( Means the name can be greater than 10; it if it more than 10 it will cause problems. In Dev C++ only go up to nine because 1 line will be null).

(Last names are typically longer than first names)

Hint: You may want to use the following I/O manipulators.

#include<iomanip.h>, setw(15), setprecision(2) setiosflags(ios::fixed|ios::showpoint|ios::left)

[What does iomanip do? It decorates nicer than iostream.h; It manipulates input and output]

 

 

DR.EBRAHIMI'S PAYROLL INSTITUTE

106 EASY WAYS

PLEASANTVILLE, N.Y. 11068

 

 

FIRST NAME              LAST NAME               STAT    SSN      HW       HR         OTH         OTP        REGP       GROSS        TAX      NET       

===========      ==========     ===    ===     ==    ===      ===     ====    ====   ======    ===    ====

JOHN                         SMITH             M       113     50       20       10        300        800     1100         385     715

JANE                          DOE                 M       223     45      15        5         112..5    675     787.5        275     512.5

 

B) Convert the program as it is to arrays. Set max size of array to 100.

    int hw[100], empid[100];

 

C) Take advantage of arrays by breaking programs into separate units. Each unit should have a

    separate loop.

 

D) Include a search by employee id. (An extra credit)

E) Include a search by employee name. (An extra credit)

F) Sort the data either by employee id or by employee name

 

April 17th

Captains: Angie Karnofsky, Ariel Candelario

Andrew DiChiara Will Demo

 

 

 

 

 

 

 

 

 

___________________________________________________________________________________________________________

 

 

April 22th

Captains: Christina Morell, Ariel Candelario, & Angie Karnofsky

 

 

Chapter 6 (page 166)

FUNCTION: ORGANIZING THE PROGRAM

 

As problems grow they become more difficult to solve. One problem solving strategy is to break a problem into smaller problems (sub-problems) then solve each of the sub-problems separately. This idea of breaking a problem into smaller ones is reminiscent of the old expression divide and conquer. Similarly, a big problem can be broken into subprograms that can be written and tested independently. Each of these subprograms is known as a function (unit) with a specific action (task) to perform. Normally, an application program (software) consists of thousands of lines of code (instructions). Without an organization (function), it is almost impossible to write, test, use, maintain, or reuse a large program. Can you imagine a team of programmers trying to write and manage a program without using functions.

 

TWO KINDS OF FUNCTIONS

 

There are two kinds of functions: built-in and user-defines functions. A built-in function is pre-constructed and is available for use in your program. A user-defined function must be built by the programmer.

 

 

C/C++ BUILT-IN FUNCTIONS

 

C/C++ comes with a library of functions that are pre-programmed and ready for use in your program. You are already familiar with the C built-in functions scanf(...), and printf(...), and the C++ function eof (...).

 

Difference between explicit and implicit.

implicit: implied, rather than expressly stated

explicit: fully and clearly expressed or demonstrated; leaving nothing merely implied; unequivocal:

 

 

Function defined explicitly:

How would you make a payroll program you have so far explicit?

Look in the book that explicitly using function.

 

Elliot Saloway is a programmer that we looked at during class.

 

Page 203 is a payroll program.

How many functions does this program have?

-There are 10 functions.

1.   Read all data

2.   Find overtime

3.   Find overtime pay

4.   Find regular hours

5.   Find regular pay

6.   Find gross pay

7.   Find tax rate

8.   Find tax amount

9.   Find net pay

10. Print all data

 

-Line 3 is a comment and it is for you and others. Compiler does not look at it. It explains what the program does.

 

- You have to specify it on the top with prototype.

 

- From what line to what line are function prototype? Lines 4 - 13.

 

- Which line does the main program start? Line 15. [when you see a void you do not need return 0, you are voiding it like you would void a check]

 

-From what line to what line are you declaring? Lines 16-25

 

-Line 28 we call function call. Lines 28-39 everything is explained there.

 

-____________________________________________________________________________________________________________________

April 2

Captains: Christina Morell,Jeffery Prudhomme

 

 

Page 203

Part 1

1,4, 13, 15 &16, 19-21, 25, 28, 37, 39

 

Page 203

Part 2:

1,4,15 & 16,19,20-24, 28-33, 37-39

 

Whoever fixes the program to have errors you will receive 2 points.

 

 

 

 

 

_________________________________________________________________________________________________________________

 

April 29, 2008

Captains: Christina Morell,Jeffery Prudhomme

 

Chapter 8: OBJECT AND CLASS: EVERYTHING AS AN OBJECT OF A CLASS.

(The idea of function is not a new way to solve problems).

 

The world around is is made of objects and each object has its own characteristics as to what it does and what can be done to it. A group of similar objects can be generated from a model (blueprint) that encompasses essential characteristics such as its data and its functionality, which is known as class. A class bundles the data, its functions, and how these two members interact with each other as well as the outside world. Introduction of class and its objects will shift the focus from Procedural Programming (with function in center) to Object Oriented Programming where security (access), extendibility (expansion), and reusability (cost) are the major concerns.  As a matter of fact, you have already dealt with class and object.  The simple cin and cout statements are objects of the iostream class

 

HOW TO MAKE A CLASS 

There are two ways to make a class, one that starts with the keyword struct and one that starts with the keyword class itself.  The following examples of employee class describe the similarities and differences between when the keyword class or the keyword struct is used. Note that the only difference between struct and class in C++ is the default accessibility of the members. By default members in struct are public, whereas members in class are private. However, you may argue that to define a class it would be easier to simply use the keyword class instead of using struct as the alternative, thus eliminating much confusion. C++ has demonstrated its loyalty to C language by extending the existing struct. A C++ programmer prefers class versus struct since the default accessibility of the members of a class is private.

 What does object mean to you?

 

Objects have two things to it:

-attribute

-functionality/method

 

Person/ Employee will be the object.

The payroll will be the class and from the class we will make an object.

Employee is an object of payroll.

 

What is the difference between this payroll program and the others payroll programs we have worked on?

In the other payroll programs we did not use object. Working with an object makes you rethink things and look at them differently.

 

(Ebrahimi is an object from the class of professors).

 

In chapter 7 objects are before structure. 

 

We could have started the first day with object but we did not have the tools. We needed to know what the data is because functions have data.

 

What makes program difficult is when something is missing.

 

Make sure you know the case studies at the end of each chapter to fully understand what we are doing.

 

 

 

 

 

 

 

 

 

 

 

Read pages 276 - 278 and case study is on page 284 !

_____________________________________________________________________

 

May 1, 2008

Captains: Jeffrey Prudhomme

 

Payroll Program With Class

This payroll program uses a payroll class; the main program creates an object of the class, called employee, and calls the printreport( ) member function to display the employee information that was retrieved from the file as well as results of calculations done in the program.

 

#include <iostream>
using namespace std;

int main(){
cout<<"HELLO"<<endl;
system ("pause");
}
 

 

 

 

 

 

 

 

 

`   

 

 

 

 

 

 

 

SUNY College at Old Westbury - School of Business

 

 

Course Number:  BU 2010

 

Course Title: Business Programming with Visualization

 

A. 1.    Course Description

            The objective of this course is to gain an understanding of programming fundamentals (concepts and constructs) and to apply them in business applications and problem solving with a visual interface. The course material will include: input/output, decision-making, repetition, file handling, and objects. Students will learn how to organize their program using functions and structures. Students are required to apply the learned material and algorithms (e.g. search) in creating a real world application such as payroll, invoice, taxation, and stock market. The course will be C/C++ based and the following visual and graphic interfaces such as CGI, Visual Basic .Net, and Java applets will be examined.

 

A. 2.    Intended Audience

            MIS majors and minors, elective (liberal arts)

 

A. 3.    Course Objectives

            Students will learn fundamental programming concepts and apply them in business applications and problem solving with a visual interface.

 

B.         Prerequisites

            none

 

C.        Mode of Instruction

            The class consists of both lecture and lab. During the lab, there will be demonstrations using a visual programming environment, as well as writing, testing, and debugging programs.

 

D.        Student Responsibilities

·         Each student will be expected to complete a series of lab assignments for each topic and one large project, preferably payroll or invoice.

·         There will be a test, midterm and final exam.

·         Students must plan to spend a minimum of two (2) hours per week outside of the class working with computer.

 

 

E.         Grading

Test 1 and 2

30%

Assignments & projects

25%

Final Exam

30%

Class Work & Attendance

15%

 

Total

 

 

100%

           

 

 

F.         Agenda

 

           

Weeks:

Topic:

Reading:

1
 

The Evolution Of Computer Programming

A Brief History on Programming Languages and OOP

Intro to Visual Studio .Net environment

 

Ch 1

2
 

Input, Process, Output (IPO)

 

Variable declaration and data types

Input Box, Message Box
Programming Events

Calculations

 

Payroll System (Phase 1)                 

 

Ch 2


3
 

Loop

 

Loop constructs

Nested loops
Loop with data file

 

Payroll System (Phase 2)

 

Ch 3

4
 

Decision Making : Making Programs Intelligent

Algorithm: Finding The Minimum And Maximum
Nested If
Logical If

 

A Simple Search Program with data file

Analysis Of An Algorithm: Speed, Space, And Complication

 

Ch 4

5

Test 1

 

Payroll System (Phase 3):

Grosspay With Overtime: If Else With Compound Statement

Extend the payroll program, to compute, over time pay, and tax amount with variable tax rates 

 

Ch 4

6


 

Chapter 5 Array - Arrangement Of Data

 

Creating and accessing arrays
Parallel arrays

 

Payroll System (Phase 4)

Ch 5

7

 

Simple Search program with arrays

Array Of Array: Two Dimensional Array

Ch 5

8

 

 

Functions

 

Payroll System (Phase 5)

Ch 6

 

 

9


Designing a user interface
Adding a Form, working with multiple forms
Modifying control properties in code

 

 

10
 

Input Box, Message Box
Programming Events

Additional Controls (Check Boxes, Radio Buttons, List Boxes, Combo Boxes)

Strings

User-defined types

 

11
 

Intro to HTML

JavaScript

VBScript

Ch 20

12
 


CGI
Java Applets 

Ch 20

13


 


Project and Review

 

14
 


 

Final

 

 

 

 

G.           Bibliography

 

            C++ Programming Easy Ways (Volume 1 & 2) Dr. A. Ebrahimi, American Press