4.5 Computer Science - Programing Courses
CS172 - Computer Science I and CS291 - Computer Science II are the first two computer science courses that students majoring in (and minoring) in Computer Science must take. These courses will present the fundamental programming concepts and methodologies in developing programs in C++. CS 172 focuses on the core concepts of structural programming and will also introduce the students to object-oriented programming concepts. CS 291 focuses on theoretical understanding of data structures, their implementation, and the object-oriented viewpoint.
OER-Enabled Pedagogy: Prompts and Examples for Computer Science - Programing Courses
The active prompts in this section can be used for CS172, CS291, and may also be applied to other computer science programming language courses. For CS172, instructors may use the following active learning prompts a week or two after the midterm exam. For CS291 and upper-level courses, instructors may start to use the active learning prompts a few weeks into the course.
OER Activity Prompt #1: Solving a real-world problem in c++
Computer programs can solve many of our everyday problems. For example, a basic calculator program can perform basic arithmetic operations like addition, subtraction, multiplication and division. A GPA calculator program can calculate your GPA from all the letter grades that you received. Determining the shortest path from a given source to a destination can also be done by a computer program. A more complex program can perform a DNA sequencing data analysis.
As an in-class exercise:
1) Form a small group of 3-4 students.
2) Think of the programming constructs and topics that you learn in the class (or as provided by your instructor). Based on these constructs/topics that you have learned, discuss (as a group) a real-world problem that you can use a computer program to solve.
3) Discuss what will be the inputs and outputs of the problem and what is the data processing needed to generate the output.
4) As a group, write a complete C++ program to solve the problem you identified in 2), with the inputs and outputs you identified in 3).
5) Write down a brief description of the program you identified in 2) and write down a step-by-step programming task instruction for your peers to solve the problem in a C++ program and submit the instruction to your instructor.
Each programming task instruction generated by each group will be distributed to other groups by the instructor as a class assignment (to be worked on within 1-2 weeks):
6) Each group will be given the programming task instructions from other groups. (In a 25-student class, each group will be working on 5-6 problems)
7) Work as a group, complete the programming tasks provided by other groups.
8) Submit your solutions in a complete C++ code to your instructor.
The instructor will post each programming task instruction and all the submitted solutions for each instruction on the Blackboard. Also, as a class assignment:
9) As a group, go through all the code submissions for your group’s problem in 2).
10) Compare and discuss other groups’ code with your own solution in 4).
- What are the good coding practices that you learn from other groups’ codes?
- What can be improved to your code based on what you learned through peers?
Worked Example for Prompt #1: Solving a real-world problem in c++
Within the students’ assigned group, they will come up with the following:
Real-world problem: To find the average score of the students in a class.
Program constructs and topics: Vector and for loop
Input: An array/vector of students score (in integer)
Output: Average score of the students
A complete C++ program:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int sum = 0;
vector<int> studentScores = {89,99,40,55,70,63,79,81,90,50};
for (int i = 0 ; i < studentScores.size() ; i++){
sum = sum + studentScores.at(i);
}
cout << "Average score of the class is: " << sum/studentScores.size() << endl;
return 0;
}
Instruction for other groups:
Write a C++ program that takes in the following scores. Make use of a vector to store all the scores of students.
{89,99,40,55,70,63,79,81,90,50}
Then find out the average scores of the students. The output should be displayed exactly as shown below:
Average score of the class is: 71
OER activity Prompt #2: Generating Questions Bank
1) The instructor lists down the detailed and specific learning objectives for the students to work on. The number of the objectives should be at least half the size of the class. The sample learning objectives are students will be able:
a) to initialize an integer variable.
b) to initialize a character variable.
c) to perform an arithmetic operation on two integers.
d) to display a product from three or more integers.
e) to prompt a user for an input.
f) to display a multi-line output to the console.
g) to use an if-statement to check for a certain value.
h) to iterate each element in an array.
i) to pass an argument to a function.
j) to sum each element in an array.
k) to search for a value in an array.
l) to change a for-loop to a while-loop construct.
m) to print out one character in a string.
n) to modify one element in a vector.
o) to write a function to perform basic arithmetic operations.
p) to write a function to calculate an average of the three numbers.
q) to write a function to print out some strings a number of times.
r) to create and use a user-defined data type using struct.
2) Instructor asks each student to choose a learning objective that is provided by the instructor. (or the instructor may assign a learning objective to each student).
3) Based on the specific learning objective assigned, each student will come up with one test question and the solution to the test question.
4) Each student will submit the test question to the instructor. (The instructor will upload all the test questions to an online platform where students can access and provide comments to the questions).
5) Each student login to the online platform in 4) and review a set of questions (as assigned by the instructor). Review and provide comments to the questions.
6) The owner of the question will review the comments, then revise as he/she sees appropriate.
7) The questions will be collected by the course instructor to be used in future classes.
Worked example for prompt #2: Generating Questions Bank
A test question for ‘Be able to iterative each element in an array.’ learning objective is shown below:
Sample Question#1: What is the output of the following code snippet?
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> myVector = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0 ; i < myVector.size() ; i=i+2){
cout << myVector[i] << " ";
}
return 0;
}
Sample Solution:
1 3 5 7 9
A test question for ‘Be able to create and use a user-defined data type using struct.’ learning objective is shown below:
Sample Question#2: Given the following struct definition and variables, complete the code in main() to print out the first name and last name of the employee.
#include <iostream>
using namespace std;
struct employee{
int emplID;
string firstname;
string lastname;
};
int main() {
employee aEmp;
aEmp.firstname = "John";
aEmp.lastname = "Doe";
return 0;
}
Sample Solution:
#include <iostream>
using namespace std;
struct employee{
int emplID;
string firstname;
string lastname;
};
int main() {
employee aEmp;
aEmp.firstname = "John";
aEmp.lastname = "Doe";
cout << "Name : " << aEmp.firstname << " " << aEmp.lastname;
return 0;
}
OER Activity Prompt #3: Tutorial Materials on s Selected Topic
1) Instructors will assess the topics that need to be readdressed in the class. This can be assessed using previous quiz/exercises or homework scores of the class.
2) Once a few topics have been selected, ask the class to vote for the topic(s) that they would like to go over again. Choose one or a few using majority rule.
3) Assign students in pairs or groups of three to create a short summary on the topic. This can be in the form of a PowerPoint presentation, video presentation or an oral presentation (if time permits).
4) All the materials will be shared and discussed in the class.
Worked Example for Prompt #3: Tutorial Materials on a Selected Topic
The instructor and students agree on the topic that they want to readdress. For example, in this case, ‘Multidimensional arrays’ was chosen.
Students will then work in pairs or in a small group to create a short summary on the topic. This example shows that the topic on ‘Multidimensional arrays’ was summarized as a PowerPoint presentation.
If time permits, the group can present their work to the class. The instructor will facilitate the discussion.
By Thitima Srivatanakul