Kudler has plenty of room to increase sales while controlling costs. The first place they should start is renegotiating the cost associated with rent in the locations where they already have stores. Since they already occupy the stores and show good payment history, they have leverage in these negotiations. They are currently paying $63,000, if they can reduce that rent by 5%, they would be saving $3,150 which is more than enough to cover their bad debts. They can also drive cost out of the business by paying back debt that has higher interest rates. Currently, Kudler is paying over $63,000 in interest while showing net income of $676,795. Some of that income should be leveraged to reduce the cost of interest. Kudler can utilize these cost controls without compromising the increase in sales.
TABLE 6
Sarah Stamm
Andrew Smith
George Denillo
Kevin Henry
Jerry Hill
7-3 What does this algorithm do?Adding 2 to the current number 10 times.
Assumptions: The user provides a positive integer.
Input:A number from user.
Output:Some result.
1. Input number from user.
2. Set count to 1.
3. While (count <= 10)
a. Set current # to # + 2
b. Set count to count + 1
4. Display current # to the screen
7-13
Create an algorithm to describe new balance after 10 transactions at new restaurant.
Assumptions: Balance never goes negative.
Step 1: Get initial balance
Step 2: Ask if there are more transactions. If not, go to step 6.
Step 3: Get transaction.
Step 4: Set balance to balance + transaction.
Step 5: Go to step 2.
Step 6: Display overall balance.
9-5
What would this SQL statement output?
Select * FROM “LOCATION”
Output: All the fields in the location table would be selected.
9-8
Which customer(s) live in Georgia (GA)? List by name.
Table name is customer, check c_state attribute to locate matching state, returns c_id # 5 (Sheila Lewis)
TABLE #5
(Emma Towe, Dieter Archer, Brian House, Davis Ruppert, Ross Bowman, Yahya Hefnawi)
MODULE 8
(8-4) Q1: What will this for loop output?
Var counter;
For(counter=7; counter >=7; counter--);
{
Document.write(“current count: “+ counter+” < br/>”);
{
Document.write(“loop stopped”);
(8-9) Q2: Create a javascript program that will convert Celsius to Fahrenheit or vice versa.
MODULE 9
(9-5) Q3: List the building code and the capacity in the location table using SQL developer.
(9-8) Q4: Create a list of all the students that live in Clermont or Carrabelle from SQL developer.
Display the S_first, S_last, and S_city
A1: Starts at 7 then decrements till -7.
A2:
var degrees;
var label;
degrees = prompt ("Please enter a temperature in degrees");
label = prompt ("Please enter 'C' for Celsius or 'F' for Fahrenheit");
if (label=="C") {
answer = ((degrees * 9/5) + 32);
document.write(degrees +" degrees C is equal to " + answer + " F");
}
else{
answer = ((degrees - 32) * 5/9);
document.write(degrees +" degrees F is equal to " + answer + " C");
}
A3: SELECT bldg_code, capacity FROM location
A4: ...
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
Kudler has plenty of room to increase sales while controlling cost.docx
1. Kudler has plenty of room to increase sales while controlling
costs. The first place they should start is renegotiating the cost
associated with rent in the locations where they already have
stores. Since they already occupy the stores and show good
payment history, they have leverage in these negotiations. They
are currently paying $63,000, if they can reduce that rent by
5%, they would be saving $3,150 which is more than enough to
cover their bad debts. They can also drive cost out of the
business by paying back debt that has higher interest rates.
Currently, Kudler is paying over $63,000 in interest while
showing net income of $676,795. Some of that income should
be leveraged to reduce the cost of interest. Kudler can utilize
these cost controls without compromising the increase in sales.
TABLE 6
Sarah Stamm
Andrew Smith
George Denillo
Kevin Henry
Jerry Hill
7-3 What does this algorithm do?Adding 2 to the current
number 10 times.
Assumptions: The user provides a positive integer.
Input:A number from user.
Output:Some result.
1. Input number from user.
2. Set count to 1.
3. While (count <= 10)
a. Set current # to # + 2
b. Set count to count + 1
4. Display current # to the screen
7-13
2. Create an algorithm to describe new balance after 10
transactions at new restaurant.
Assumptions: Balance never goes negative.
Step 1: Get initial balance
Step 2: Ask if there are more transactions. If not, go to step 6.
Step 3: Get transaction.
Step 4: Set balance to balance + transaction.
Step 5: Go to step 2.
Step 6: Display overall balance.
9-5
What would this SQL statement output?
Select * FROM “LOCATION”
Output: All the fields in the location table would be selected.
9-8
Which customer(s) live in Georgia (GA)? List by name.
Table name is customer, check c_state attribute to locate
matching state, returns c_id # 5 (Sheila Lewis)
TABLE #5
(Emma Towe, Dieter Archer, Brian House, Davis Ruppert, Ross
Bowman, Yahya Hefnawi)
MODULE 8
(8-4) Q1: What will this for loop output?
Var counter;
For(counter=7; counter >=7; counter--);
{
Document.write(“current count: “+ counter+” < br/>”);
{
Document.write(“loop stopped”);
3. (8-9) Q2: Create a javascript program that will convert Celsius
to Fahrenheit or vice versa.
MODULE 9
(9-5) Q3: List the building code and the capacity in the location
table using SQL developer.
(9-8) Q4: Create a list of all the students that live in Clermont
or Carrabelle from SQL developer.
Display the S_first, S_last, and S_city
A1: Starts at 7 then decrements till -7.
A2:
var degrees;
var label;
degrees = prompt ("Please enter a temperature in degrees");
label = prompt ("Please enter 'C' for Celsius or 'F' for
Fahrenheit");
4. if (label=="C") {
answer = ((degrees * 9/5) + 32);
document.write(degrees +" degrees C is equal to " + answer + "
F");
}
else{
answer = ((degrees - 32) * 5/9);
document.write(degrees +" degrees F is equal to " + answer + "
C");
}
A3: SELECT bldg_code, capacity FROM location
A4: STUDENT
S_last
S_first
S_city
Perez
Jorge
Clermont
Marsh
John
Carrabelle
SQL SELECT S_first, S_last, S_city FROM student WHERE
S_city= ‘Clermont’ OR S_city= ‘Carrabelle’
Alan Berens
Joshua Rowland
Mohammed Abukhalil
Austin Barnes
Nandi Baccus
Eric Sowers
5. Questions:
8-9. Students will be able to construct or evaluate Javascript
statements that include ifthen,
if-then-else, if-then-else if, or looping statements.
Students will be able to determine when an expression results in
NaN in Javascript.
8-6. Students will be able to evaluate and determine the output
for statements that include
Strings, numbers, and associated functions.
7-13. Students will be able to construct an algorithm in English
to solve a particular
problem.
7-24. Be able to apply either a sequential search or a binary
search to an array of items.
Answers:
8-9
Var x = prompt(‘enter an integer’);
If (x<0) {
Alert(red);
}else if(x<20){
Alert(‘blue);
}else if(x==20&&(!false)){
6. Alert(‘green’);
}else{
Alert(‘NOICE!!’);
}
What is the output when x is 69?
7-24
Sequential searches move through an array one at a time until
the item is found. Binary searches move through an array. It
moves to the Midpoint of the array and excludes large amounts
of the array. It moves to the midpoint of the array and excludes
the part that is not included, then moves to the midpoint of the
array that is left. It continues until the item is found.
8-6
Which customer(s) ordered there items from the summer 2006
order source on June 1st?
Tables:Order_Source, Orders, Customers
Attributes:Os_Desc, OS_ID, O_Date,, C_ID
C_Last, C_First
Result:Paul Phelps
7-13
Step 1 Exit the building
Step 2 Make sure you exit the building from front
Step 3 If you exit from the otherside go back inside and exit
from front
Step 4 Go east with colonel glenn hwy
Step 5 go south with Fairfield rd
The mall will be on your right after 5 traffic lights
Ballester, Francis
Ford, Sam
Francis, Rizia
Horstman, Clayton
7. Nikdoost, Allen
O’Connor, KrisQuestions
Module 7
1. Define Pseudocode
13. Create an algorithm for identifying complaints in a
satisfaction survey (assume a 10-point scale, with answers of 3
or less considered a complaint)
Module 9
5. Create SQL statement to identify courses that are taught by
Mark Zhulin and James Sealy.
6. List the first and last name of each student followed by the
faculty ID from the student table and the faculty name of their
faculty advisor.
Answers
Module 7:
1. Pseudo code is simplified program design language, designed
primarily for human reading.
13. Algorithm for identifying complaints:
i. When answer is less than 4, flag response as a complaint.
ii. Ask “Why dissatisfied?”
Module 9:
5. SELECT * FROM COURSE_SECTION WHERE F_ID = '3'
OR F_ID = '5';
6. SELECT student.s_first, student.s_last, student.f_id,
faculty.f_last FROM student inner join faculty on
student.f_id=faculty.f_id;
1
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
8. CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Module 9 – Databases
Instructor: Kera Watkins
479 Joshi Research Center
937-775-5138
[email protected]
CS1150 Intro to Computer Science
Sources: Jones & Bartlett Learning;
Nell Dale and John Lewis – Computer Science Illuminated;
Karen Myers – Wright State University;
Vance Saunders – Wright State University
mailto:[email protected]
2
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Goals
l Describe the elements of a database management
9. system
l Describe the organization of a relational database
l Establish relationships among elements in a
database
l Write basic SQL statements
2
3
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Managing Information
Information system
Software that helps the user organize and analyze data
Database management systems
Software tools that allow the user to organize, manage,
and analyze data in various ways
3
10. 4
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
(DBMS)
Database
A structured set of data
Database management system (DBMS)
A combination of software and data, made up of
– a physical database
– a database engine
– database schema
Physical database
A collection of files that contain the data
4
11. 5
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
(DBMS)
Database engine
Software that supports access to and modification of the
database contents
Database schema
A specification of the logical structure of the data stored in
the database
Database query
A request to retrieve data from a database
5
6
Wright State University, Department of Computer Science
12. Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
6
________
7
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Relational Model
Relational DBMS
A DBMS in which the data items and the relationships among
them are organized into tables
Tables
13. A collection of records
Records (object, entity)
A collection of related fields that make up a single database
entry
Fields (attributes)
A single value in a database record
7
8
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Table
102 Back to the
Future
comedy
adventure
PG
14. • Record
• Database Object
• Entity
9
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Table: Movie
9
10
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Database Table Key
15. Key
One or more fields of a database record that uniquely
identifies it among all other records in the table
We can express the schema for this part of the database
as follows:
Movie (MovieId:key, Title, Genre, Rating)
In general:
TableName (colHdr_1, colHdr_2, colHdr_3, …, colHdr_i:key,
…, colHdr_m)
11
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Database Table: Customer Table
12
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
16. CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Relationships
Customer
Table
Movie
Rental Table
13
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Table: Movie
14
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
17. CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Structured Query Language
Structured Query Language (SQL)
A comprehensive relational database language for
data manipulation and queries
SELECT attribute-list FROM table-list WHERE condition
name of field name of table value restriction
SELECT title FROM movie WHERE rating = 'PG'
Result is a table containing all PG movies in table “movie”
15
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
18. Table Challenge Queries in SQL 1
l SELECT name, address FROM customer
– English: Provide the fields from the name and address
columns for each
record from the customer table.
Result Table
Draw the Result Table
16
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Table Challenge: Queries in SQL 2
l SELECT * FROM movie WHERE genre LIKE '%action%‘
– English: Provide each record from the movie table where the
genre
column contains “action”. Circle the Records for the Result
Table
19. 17
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Table Challenge: Queries in SQL 3
l SELECT * FROM movie WHERE rating = ‘PG-13' ORDER
BY title
– English: Provide each record from the movie table where the
rating is
“PG-13”. List them in alphabetical order based on the title.
Number the Rows for the Result Table
18
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Table Extra Challenge – 10 pts quiz:
20. What is the SQL Statement?
MovieId Title Genre Rating
5022 Elizabeth drama period R
104 Field of Dreams fantasy drama PG
7442 Platoon action drama war R
Result Table
19
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Modifying Database Content
INSERT INTO customer VALUES (9876, 'John Smith', '602
Greenbriar
Court', '2938 3212 3402 0299')
UPDATE movie SET genre = 'thriller drama' WHERE title =
'Unbreakable‘
DELETE FROM movie WHERE rating = 'R'
21. 1
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Module 9 Part 2 – Databases
Instructor: Kera Watkins
479 Joshi Research Center
937-775-5138
[email protected]
CS1150 Intro to Computer Science
Sources: Jones & Bartlett Learning;
Nell Dale and John Lewis – Computer Science Illuminated;
Karen Myers – Wright State University;
Vance Saunders – Wright State University
mailto:[email protected]
2
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
22. CS1150
Introduction to Computer Science
Goals
l Establish relationships among elements in a
database
l Practice writing basic SQL statements
2
3
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Table Relationships
l Clearwater and Northwood are available via SQL Developer
l Color code the attributes related to one another in
different tables
l Quick! How many relationships between tables can you
find?!!
23. 4
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Answer the following questions using the Clearwater db
sheet. (need to identify table names, attribute names, key
relationships)
1. Which customer(s) live in Georgia(GA)? List by name.
Table name is customer, check c_state attribute to locate
matching state, returns c_id # 5 (Sheila Lewis)
2. How many customers placed an order on May 2006?
a. What are their names?
3. How many 3-Season Tents are left in stock?
4. Which customer (s) ( first and last names) placed orders
from the “Web Site” order source?
5. Which specific items of the women’s clothing category
were sold between May 29th and May 31st inclusive?
4
24. 5
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Using Column Aliases
l When column names are not descriptive or calculations are
made, it is helpful to alias the column
l After the column specification enter the keyword AS
followed by the column alias, may embed in “ “ if it
contains spaces
Example:
select os_id as “Order Source ID” from orders;
5
6
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
25. CS1150
Introduction to Computer Science
Group Functions – used to summarize or
group records
l SUM
l COUNT
l AVERAGE
l MAX
l MIN
l etc.
eg. SELECT SUM(inv_qoh) AS “Total Inventory” FROM
inventory;
6
7
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
26. Using Oracle SQL Developer
Run the application
Login by clicking on the + sign next to cseora11(below
Connections on the left hand side of the screen)
Your username is S1(this is already entered)
Your password is: tiger9
7
8
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Querying data that requires access to 2 or
more tables(Inner Join)
Syntax:
select column(s) from Table1, Table2
where table1.PK = table2.FK [and
27. column=search condition];
– [ ] brackets indicate optional clause
– Example:
l List the first and last named of the students advised by faculty
ID = 1,
(Teresea Marx)
SELECT s_last, s_first FROM student, faculty WHERE
faculty.f_id
= student.f_id AND student.f_id = 1;
8
9
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Create the SQL Statements!
1. Which customer(s) live in Georgia(GA)? List by name.
Table name is customer, check c_state attribute to locate
matching state, returns c_id # 5 (Sheila Lewis)
2. How many customers placed an order on May 2006?
28. a. What are their names?
3. How many 3-Season Tents are left in stock?
4. Which customer (s) ( first and last names) placed orders
from the “Web Site” order source?
5. Which specific items of the women’s clothing category
were sold between May 29th and May 31st inclusive?
9
10
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Summary
l Saw how different tables relate to one another
l Practiced writing SQL statements using JOINS and
group functions
10
29. 1
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Module 9 Part 2 – Databases
Instructor: Kera Watkins
479 Joshi Research Center
937-775-5138
[email protected]
CS1150 Intro to Computer Science
Sources: Jones & Bartlett Learning;
Nell Dale and John Lewis – Computer Science Illuminated;
Karen Myers – Wright State University;
Vance Saunders – Wright State University
mailto:[email protected]
2
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
30. Introduction to Computer Science
Goals
l Establish relationships among elements in a
database
l Practice writing basic SQL statements
2
3
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Table Relationships
l Clearwater and Northwood are available via SQL Developer
l Color code the attributes related to one another in
different tables
l Quick! How many relationships between tables can you
find?!!
31. 4
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Answer the following questions using the Clearwater db
sheet. (need to identify table names, attribute names, key
relationships)
1. Which customer(s) live in Georgia(GA)? List by name.
Table name is customer, check c_state attribute to locate
matching state, returns c_id # 5 (Sheila Lewis)
2. How many customers placed an order on May 2006?
a. What are their names?
3. How many 3-Season Tents are left in stock?
4. Which customer (s) ( first and last names) placed orders
from the “Web Site” order source?
5. Which specific items of the women’s clothing category
were sold between May 29th and May 31st inclusive?
4
5
32. Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Using Column Aliases
l When column names are not descriptive or calculations are
made, it is helpful to alias the column
l After the column specification enter the keyword AS
followed by the column alias, may embed in “ “ if it
contains spaces
Example:
select os_id as “Order Source ID” from orders;
5
6
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
33. Introduction to Computer Science
Group Functions – used to summarize or
group records
l SUM
l COUNT
l AVERAGE
l MAX
l MIN
l etc.
eg. SELECT SUM(inv_qoh) AS “Total Inventory” FROM
inventory;
6
7
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Using Oracle SQL Developer
34. Run the application
Login by clicking on the + sign next to cseora11(below
Connections on the left hand side of the screen)
Your username is S1(this is already entered)
Your password is: tiger9
7
8
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Querying data that requires access to 2 or
more tables(Inner Join)
Syntax:
select column(s) from Table1, Table2
where table1.PK = table2.FK [and
column=search condition];
35. – [ ] brackets indicate optional clause
– Example:
l List the first and last named of the students advised by faculty
ID = 1,
(Teresea Marx)
SELECT s_last, s_first FROM student, faculty WHERE
faculty.f_id
= student.f_id AND student.f_id = 1;
8
9
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Create the SQL Statements!
1. Which customer(s) live in Georgia(GA)? List by name.
Table name is customer, check c_state attribute to locate
matching state, returns c_id # 5 (Sheila Lewis)
2. How many customers placed an order on May 2006?
a. What are their names?
36. 3. How many 3-Season Tents are left in stock?
4. Which customer (s) ( first and last names) placed orders
from the “Web Site” order source?
5. Which specific items of the women’s clothing category
were sold between May 29th and May 31st inclusive?
9
10
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Summary
l Saw how different tables relate to one another
l Practiced writing SQL statements using JOINS and
group functions
10
3/11/2015
37. 1
1
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Module 9 – Databases
Instructor: Kera Watkins
479 Joshi Research Center
937-775-5138
[email protected]
CS1150 Intro to Computer Science
Sources: Jones & Bartlett Learning;
Nell Dale and John Lewis – Computer Science Illuminated;
Ray Toal and Joh David N. Dioniso – The Javascript
Programming Language;
Karen Myers – Wright State University;
Vance Saunders – Wright State University
2
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
38. Introduction to Computer Science
Chapter Goals
l Describe the elements of a database management
system
l Describe the organization of a relational database
l Establish relationships among elements in a
database
l Write basic SQL statements
2
3
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Managing Information
Information system
Software that helps the user organize and analyze data
Electronic spreadsheets and database management
systems
39. Software tools that allow the user to organize, manage,
and analyze data in various ways
3
mailto:[email protected]
3/11/2015
2
4
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
(DBMS)
Database
A structured set of data
Database management system (DBMS)
A combination of software and data, made up of
– a physical database
40. – a database _______________
– database _________________
Physical database
A collection of files that contain the data
4
5
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
(DBMS)
Database engine
Software that supports access to and _________ of the
database contents
Database schema
A specification of the _______________ of the data stored in
the database
Database query
41. A request to retrieve data from a database
5
6
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Database Management Systems
6
________
3/11/2015
3
7
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
42. Introduction to Computer Science
The Relational Model
Relational DBMS
A DBMS in which the data items and the relationships among
them are organized into tables
Tables
A collection of records
Records (object, entity)
A collection of related fields that make up a single database
entry
Fields (attributes)
A single value in a database record
7
8
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Database Table
43. 8
9
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Database Table
Key
One or more fields of a database record that uniquely
identifies it among all other records in the table
We can express the schema for this part of the database
as follows:
Movie (MovieId:key, Title, Genre, Rating)
9
3/11/2015
4
10
Wright State University, Department of Computer Science
44. Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Database Table
10
Figure 12.8 A database table containing customer data
11
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Relationships
11
12
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
45. CS1150
Introduction to Computer Science
Structured Query Language
Structured Query Language (SQL)
A comprehensive relational database language for
data manipulation and queries
SELECT attribute-list FROM table-list WHERE condition
name of field name of table value restriction
SELECT title FROM movie WHERE rating = 'PG'
Result is a table containing all PG movies in table ‘movie’
12
3/11/2015
5
13
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
46. Introduction to Computer Science
Queries in SQL
SELECT name, address FROM customer
SELECT * FROM movie WHERE genre LIKE '%action%'
SELECT * FROM movie WHERE rating = ‘PG-13' ORDER BY
title
13
14
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Modifying Database Content
INSERT INTO customer VALUES (9876, 'John Smith', '602
Greenbriar
Court', '2938 3212 3402 0299')
UPDATE movie SET genre = 'thriller drama' WHERE title =
'Unbreakable‘
DELETE FROM movie WHERE rating = 'R'
47. 14
2/18/2015
1
1
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Module 7 – Problem Solving
and Algorithms
Instructor: Kera Watkins
479 Joshi Research Center
937-775-5138
[email protected]
CS1150 Intro to Computer Science
Sources: Jones & Bartlett Learning;
Nell Dale and John Lewis – Computer Science Illuminated;
Karen Myers – Wright State University;
Vance Saunders – Wright State University
2
Wright State University, Department of Computer Science
48. Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Chapter Goals
Distinguish between a simple type and a composite type
Describe two composite data-structuring mechanisms
Distinguish between an unsorted array and a sorted array
Be able to apply an insertion sort to an array of items by
hand
Be able to apply either a sequential search or a binary
search to an array of items
Demonstrate an understanding of different algorithms by
hand-simulating them with a sequence of items
2
3
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
49. Introduction to Computer Science
Problem Solving
Problem solving
The act of finding a solution to a perplexing, distressing,
vexing, or unsettled question
How do you define problem solving?
3
mailto:[email protected]
2/18/2015
2
4
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Problem Solving
How do you solve problems?
50. Understand the problem
Devise a plan
Carry out the plan
Look back
4
5
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Strategies
Ask questions!
– What do I know about the problem?
– What is the information that I have to process in order the
find the
solution?
– What does the solution look like?
– What sort of special cases exist?
– How will I recognize that I have found
51. the solution?
5
6
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Strategies
Ask questions! Never reinvent the wheel!
Similar problems come up again and again in different guises
A good programmer recognizes a task or subtask that has
been solved before and plugs in the solution
Can you think of two similar problems?
6
2/18/2015
3
7
Wright State University, Department of Computer Science
52. Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Strategies
Divide and Conquer!
Break up a large problem into smaller units and solve each
smaller problem
– Applies the concept of abstraction
– The divide-and-conquer approach can be applied over and
over
again until each subtask is manageable
7
8
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Computer Problem-Solving
53. 8
Analysis and Specification Phase
Analyze
Specification
Algorithm Development Phase
Develop algorithm
Test algorithm
Implementation Phase
Code algorithm
Test algorithm
Maintenance Phase
Use
Maintain
9
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
54. Introduction to Computer Science
Phase Interactions
9
2/18/2015
4
10
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Algorithms
Algorithm
A set of unambiguous instructions for solving a
problem or subproblem in a finite amount of time
using a finite amount of data
Abstract Step
An algorithmic step containing unspecified details
Concrete Step
55. An algorithm step in which all details are specified
10
11
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Developing an Algorithm
Two methodologies used to develop computer
solutions to a problem
– Top-down design focuses on the tasks to be done
– Object-oriented design focuses on the data involved in the
solution
(We will discuss this design in Ch. 9)
11
12
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
56. Introduction to Computer Science
Summary of Methodology
Analyze the Problem
Understand the problem!!
Develop a plan of attack
List the Main Tasks (becomes Main Module)
Restate problem as a list of tasks (modules)
Give each task a name
Write the Remaining Modules
Restate each abstract module as a list of tasks
Give each task a name
Re-sequence and Revise as Necessary
Process ends when all steps (modules) are concrete
12
2/18/2015
5
13
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
57. Intro to Programming
CS1150
Introduction to Computer Science
Top-Down Design
Process continues for as many levels as it takes to make every
step concrete
Name of (sub)problem at one level becomes a module at next
lower level
13
14
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Control Structures
Control structure
An instruction that determines the order in which other
instructions in a program are executed
Can you name the ones we defined in the functionality of
pseudocode?
58. 14
15
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Selection Statements
15
Flow of control of if statement
2/18/2015
6
16
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
59. 16
Algorithm with Selection
Problem: Write the appropriate dress for a given
temperature.
Write "Enter temperature"
Read temperature
Determine Dress
17
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
17
Algorithm with Selection
IF (temperature > 90)
Write “Texas weather: wear shorts”
ELSE IF (temperature > 70)
Write “Ideal weather: short sleeves are fine”
60. ELSE IF (temperature > 50)
Write “A little chilly: wear a light jacket”
ELSE IF (temperature > 32)
Write “Philadelphia weather: wear a heavy coat”
ELSE
Write “Stay inside”
Determine Dress
18
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Looping Statements
18
Flow of control of while statement
2/18/2015
7
61. 19
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Looping Statements
19
Set sum to 0
Set count to 1
While (count <= limit)
Read number
Set sum to sum + number
Increment count
Write "Sum is " + sum
Why is it
called a
count-controlled
loop?
A count-controlled loop
62. 20
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Looping Statements
20
Set sum to 0
Set allPositive to true
WHILE (allPositive)
Read number
IF (number > 0)
Set sum to sum + number
ELSE
Set allPositive to false
Write "Sum is " + sum
Why is it
called an
63. event-controlled
loop?
What is the
event?
An event-controlled loop
21
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Composite Data Types
Records
A named heterogeneous collection of items in which
individual items are accessed by name. For example,
we could bundle name, age and hourly wage items
into a record named Employee
Arrays
A named homogeneous collection of items in which
an individual item is accessed by its position (index)
within the collection
21
64. 2/18/2015
8
22
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Composite Data Types
Employee
name
age
hourly/Wage
Following algorithm, stores values into the fields of record:
Employee employee // Declare and Employee variable
Set employee.name to “Frank Jones”
Set employee.age to 32
Set employee.hourlyWage to 27.50
22
23
Wright State University, Department of Computer Science
65. Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Composite Data Types
23
numbers[0]
numbers[4]
24
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Arrays
As data is being read into an array, a counter is
updated so that we always know how many data
items were stored
If the array is called list, we are working with
66. list[0] to list[length-1] or
list[0]..list[length-1]
24
2/18/2015
9
25
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
An Unsorted Array
25
data[0]...data[length-1]
is of interest
26
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
67. Intro to Programming
CS1150
Introduction to Computer Science
26
Composite Data Types
integer data[20]
Write “How many values?”
Read length
Set index to 0
WHILE (index < length)
Read data[index]
Set index to index + 1
Fill array numbers with limit values
27
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
68. Sequential Search of an Unsorted Array
A sequential search examines each item in turn and
compares it to the one we are searching.
If it matches, we have found the item. If not, we look
at the next item in the array.
We stop either when we have found the item or
when we have looked at all the items and not
found a match
Thus, a loop with two ending conditions
27
2/18/2015
10
28
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Sequential Search Algorithm
Set Position to 0
69. Set found to FALSE
WHILE (position < length AND NOT found )
IF (numbers [position] equals searchitem)
Set Found to TRUE
ELSE
Set position to position + 1
28
29
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Booleans
Boolean Operators
A Boolean variable is a location in memory that can contain
either
true or false
Boolean operator AND returns TRUE if both operands are true
and FALSE otherwise
70. Boolean operator OR returns TRUE if either operand is true and
FALSE otherwise
Boolean operator NOT returns TRUE if its operand is false and
FALSE if its operand is true
29
30
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Sorted Arrays
The values stored in an array have unique keys of a type
for which the relational operators are defined
Sorting rearranges the elements into either ascending or
descending order within the array
A sorted array is one in which the elements are in order
30
2/18/2015
71. 11
31
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Sequential Search in a Sorted Array
If items in an array are sorted, we can stop
looking when we pass the place where the
item would be it were present in the array
31
Is this better?
32
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
A Sorted Array
72. 32
A sorted array of
integers
33
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
33
A Sorted Array
Read in array of values
Write “Enter value for which to search”
Read searchItem
Set found to TRUE if searchItem is there
IF (found)
Write “Item is found”
ELSE
Write “Item is not found”
73. 2/18/2015
12
34
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
34
A Sorted Array
Set found to TRUE if searchItem is there
Set index to 0
Set found to FALSE
WHILE (index < length AND NOT found)
IF (data[index] equals searchItem)
Set found to TRUE
ELSE IF (data[index] > searchItem)
Set index to length
74. ELSE
Set index to index + 1
35
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Binary Search
Sequential search
Search begins at the beginning of the list and
continues until the item is found or the entire list has
been searched
Binary search (list must be sorted)
Search begins at the middle and finds the item or
eliminates half of the unexamined items; process is
repeated on the half where the item might be
35
Say that again…
36
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
75. CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Binary Search
36
Set first to 0
Set last to length-1
Set found to FALSE
WHILE (first <= last AND NOT found)
Set middle to (first + last)/ 2
IF (item equals data[middle]))
Set found to TRUE
ELSE
IF (item < data[middle])
Set last to middle – 1
ELSE
Set first to middle + 1
76. RETURN found
2/18/2015
13
37
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Binary Search
37
Figure 7.10 Trace of the binary search
38
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
77. Binary Search
38
Table 7.1 Average Number of Comparisons
Is a binary search
always better?
39
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Sorting
Sorting
Arranging items in a collection so that there is an
ordering on one (or more) of the fields in the items
Sort Key
The field (or fields) on which the ordering is based
Sorting algorithms
Algorithms that order the items in the collection based
on the sort key
78. 39
Why is sorting important?
2/18/2015
14
40
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Insertion Sort
If you have only one item in the array, it is already
sorted.
If you have two items, you can compare and swap
them if necessary, sorting the first two with
respect to themselves.
Take the third item and put it into its place relative to
the first two
Now the first three items are sorted with respect to
one another
79. 40
41
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Insertion Sort
The item being added to the sorted portion can be
bubbled up as in the bubble sort
41
42
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Insertion Sort
InsertionSort
Set current to 1
WHILE (current < length)
80. Set index to current
Set placeFound to FALSE
WHILE (index > 0 AND NOT placeFound)
IF (data[index] < data[index – 1])
Swap data[index] and data[index – 1]
Set index to index – 1
ELSE
Set placeFound to TRUE
Set current to current + 1
42
2/18/2015
15
43
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Subprogram Statements
We can give a section of code a name and use that name as a
81. statement in another part of the program
When the name is encountered, the processing in the other
part of the program halts while the named code is executed
43
Remember?
44
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Subprogram Statements
What if the subprogram needs data from the calling
unit?
Parameters
Identifiers listed in parentheses beside the subprogram
declaration; sometimes called formal parameters
Arguments
Identifiers listed in parentheses on the subprogram
call; sometimes called actual parameters
44
82. 45
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Subprogram Statements
45
Figure 7.14 Subprogram flow of control
2/18/2015
16
46
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Subprogram Statements
83. 46
47
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
Important Threads
Information Hiding
The practice of hiding the details of a module with
the goal of controlling access to it
Abstraction
A model of a complex system that includes only the
details essential to the viewer
Information Hiding and Abstraction are two sides of
the same coin
47
48
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
84. Intro to Programming
CS1150
Introduction to Computer Science
Important Threads
Identifiers
Names given to data and actions, by which
– we access the data and
Read firstName, Set count to count + 1
– execute the actions
Split(splitVal)
Giving names to data and actions is a form of abstraction
48
3/9/2015
1
The Espresso Program
computes ? The price
of an espresso drink
85. – The price of drink
– The size of drink
– The number of shots
– Plus tax
The following slides with a black
background are adapted from Pearson
Addison Wesley with permission of book
rep.
15
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Espresso Program
executed with the
purchase of a double tall
latte:
The test drink ==
"espresso" fails, because
86. the variable drink has
the value "latte“
The ‘then’ statement is
skipped
• double
• 2 shots
• tall
• 12 oz
16
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Espresso Program
f a
double tall latte:
2. Line 4 is executed:
The test drink ==
"latte" || drink ==
"cappuccino“ has a
true outcome
3/9/2015
87. 2
17
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Espresso Program
double tall latte:
3. Line 4a is executed:
The ounce == 8 test is
false, so the then
statement is
skipped
4. Line 4b is true:
The ounce == 12 test
has price = 2.35
18
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
88. CS1150
Introduction to Computer Science
The Espresso Program
double tall latte:
5. Line 4c is executed:
The ounce == 16 test
fails, so its then
statement is skipped
6. Line 5 is executed:
The drink ==
"Americano" test fails,
so its then statement
is skipped
19
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Espresso Program
double tall latte:
89. 7. Line 6 is executed:
This causes the value
of shots minus 1 to be
multiplied by .50,
resulting in the value
.50, which is added to
price, yielding price
⇐⇒ 2.85
3/9/2015
3
20
Wright State University, Department of Computer Science
Dr. Kera Z. Watkins, Computer Science & Engineering
CS1160
Intro to Programming
CS1150
Introduction to Computer Science
The Espresso Program
double tall latte:
8. Line 7 is executed:
Current value of price
is multiplied by
taxRate, resulting in
0.25, which is added
90. to price to compute
the final value of 3.10,
which is assigned to
price
CS1150 Introduction to Computer Science
Exam #2 Review - Algorithm Practice Problems
A
Solution
1. Create an algorithm to describe how to balance a checkbook
for a company that has more than 100
transactions.
Assumptions: Company has enough money to not go into the
negative with all their transactions.
Input: Initial balance from the user. Individual transactions
from the user.
Output: New balance after each transaction.
Step 1. Get the initial balance.
91. Step 2. Ask the user if there are any other transactions. If not
then go to Step 6.
Step 3. Get a transaction.
Step 4. Update the balance to be balance – tranaction.
Step 5. Go to Step 2.
Step 6. Tell the company user that the balancing is complete.
2. What does this algorithm do?
Assumptions: The user provides a positive integer.
Input: A number from the user.
Output: Some result.
Get a number from the user. // Step 1.
Set result and count to 1. // Step 2.
while (count <= 3) // Step 3.
Set result to result * number. // Step 4.
Set count to count + 1. // Step 5.
Provide the result to the user. // Step 6.
This algorithm calculates the cube of a number.
92. CS1150 Introduction to Computer Science
Exam #2 Review
Group Activity – 3 Quizzes * 10 pts Each!
(Only students present from begin to end are eligible to receive
credit for this activity.)
You will have the full class period to complete the exam.
You will have 50 multiple choice and
true/false questions. You will be allowed to bring one 8.5” by
11” reference sheet with anything hand-
written by you on the front only. These sheets will be turned in
with your exam. No photocopied or
printed materials are allowed. No books, Internet, notes,
calculators, electronic devices, or any other
materials beyond the single reference sheet are allowed. Please
place all materials under your desk
before beginning your exam. You may bring one additional
blank sheet for scratch paper.
Group Activity
A. Choose one person at your table to create a Word document
called table_#_exam2_review.docx
93. (replacing # with the table number). Record all present members
on your document at the top.
B. Each table has been assigned to create problems based on
the highlighted objectives for the
modules listed below. Choose who will work on each module.
Students at each table are to
work in groups of 2-3.
C. Create 2 problems and solutions based on the
Highlighted objectives that may appear on a
written exam (not multiple choice or true/false). Give them to
the table representative to record
on your document. The table rep should list solutions on a
different page of the document than
the questions.
D. Project your questions on the screen. As a table, review the
questions and discuss the answers.
E. Before the end of class, email a copy of your organized
objectives, questions, and answers to
the instructor in one consolidated file.
94. Module 7 Objectives (Tables 1, 2, 4)
7-1. Students will be able to define pseudocode.
7-2. Students will be able to distinguish among using English,
pseudocode, or a high level
language for solving the problem in terms of language
(ambiguity in English), rules (syntax
in high level language), and anything in-between (pseudocode).
7-3. Students will be able to determine the results in English of
following a particular
algorithm – which includes selection and loops (shown in
English).
7-4. Students will be able to list the main operations that a
computer can perform.
7-5. Students will be able to list and describe the phases of
computer problem-solving.
7-6. Students will be able to list and describe strategies for
problem-solving.
7-7. Students will be able to determine the correct flow of phase
interactions for problem-
solving.
7-8. Students will be able to understand the concepts of an
95. algorithm.
7-9. Students will be able to understand and implement the
concept of a top down approach for a
particular problem.
7-10. Given an algorithm in English, students will be able to
reconstruct the algorithm using
selection and/or looping statements where appropriate and vice
versa.
7-11. Students will be able to distinguish between following an
algorithm and developing one.
7-12. Students will be able to describe the pseudocode
constructs used in expressing an algorithm.
7-13. Students will be able to construct an algorithm in English
to solve a particular
problem.
7-14. Students will be able to design and implement a test plan
for a small algorithm.
7-15. Students will be able to distinguish between a simple type
and a composite type.
96. 7-16. Students will be able to describe and distinguish between
two composite data-structuring
mechanisms.
7-17. Given a particular composite data structure, students will
be able to determine if the
structure is a record or an array, along with the reason.
7-18. Given an array, students will be able to determine the
length of the array and the
index number of any element – including an array of arbitrary
length.
7-19. Students will be able to distinguish between an unsorted
array and a sorted array.
7-20. Students will be able to choose and/or implement
appropriate, efficient searching
techniques among sequential search or binary search for an
unsorted or sorted array.
7-21. Students will be able to determine the display and/or
correct result when subprograms
are used.
7-22. Students will be able to determine the number of checks
97. needed to find a particular
item within and array of items using sequential or binary search.
7-23. Students will be able to determine the state of an array
after each iteration of an
insertion sort.
7-24. Be able to apply either a sequential search or a binary
search to an array of items.
7-25. Students will be able to trace through a particular
algorithm and provide the results.
Module 8 Objectives (Tables 2, 4, 5)
8-1. Students will be able to determine the history and modern
day uses of Javascript.
8-2. Students will be able to use Javascript constructs for input
and output to perform a particular
task.
8-3. Students will be able to describe how to use comments in
Javascript and why they are
needed.
8-4. Students will be able to implement Javascript while loops
or for loops to solve a
98. particular problem.
8-5. Students will be able to use a combination of variables,
when needed, Strings, numbers, and
their associated functions to perform a particular task.
8-6. Students will be able to evaluate and determine the output
for statements that include
Strings, numbers, and associated functions.
8-7. Students will be able to evaluate a Javascript expression
using any combination of
relational, logical, and/or arithmetic operations acted upon
Strings and/or numbers.
8-8. Students will be able to determine when an expression
results in NaN in Javascript.
8-9. Students will be able to construct or evaluate Javascript
statements that include if-
then, if-then-else, if-then-else if, or looping statements.
8-10. Students will be able to construct output statements using
either alert (and 'n') or
document.write (and <br>).
99. Module 9 Objectives (Tables 1, 4, 5)
9-1. Students will be able to name and describe the elements of
a database management system.
9-2. Students will be able to pinpoint candidate attributes for a
primary key and why.
9-3. Students will be able to describe the organization of a
relational database.
9-4. Students will be able to establish relationships among
elements in a database.
9-5. Students will be able to write basic SQL statements for one
or more tables within a
database.
9-6. Students will be able to write or evaluate basic SQL
statements that modify database
content.
9-7. Students will be able to evaluate basic SQL statements.
9-8. Students will be able to determine the resulting table from
a basic SQL statement.