New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

CS 162, Week 2 Notes

by: Parker Moore

CS 162, Week 2 Notes CS 162

Parker Moore
GPA 3.82

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Notes covering arrays, functions and making algorithms. I also included a program I made a year ago that will give you an example of functions and arrays and how they work. This program also has an...
Karla Fant
Class Notes
Intro to Computer Science; Computer Science
25 ?





Popular in Computer science

This 5 page Class Notes was uploaded by Parker Moore on Sunday October 9, 2016. The Class Notes belongs to CS 162 at Portland State University taught by Karla Fant in Fall 2016. Since its upload, it has received 57 views. For similar materials see INTRO TO COMPUTER SCIENCE II in Computer science at Portland State University.


Reviews for CS 162, Week 2 Notes


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/09/16
CS 162 Week 2 PSU: Fall term Array­  *first element of an array = 1 To read in multiple words in an array: Cin.get(name, 21, ‘\n’) which is the name of the array, the size of the array, and a single character used to stop the input(‘\n’ is equivalent to pressing enter) Copy array: strcpy(name, “Karla Fant”); Length of array: strlen(name); Resources: *TIP: My recommendation is to briefly look over these resources and decide which  would work best for you. Feel free to study all in depth but if a video works better for  you than reading (or vice versa) I have included both. Also reviewing the instructor  Creating functions ­ YouTube: Here is a link to beginner c++ programming. It’s a 30 minute video but I think it helps reinforce the basic concepts.­5UtvDN0 Creating functions ­­87KQS­rZCA Algorithm *TIP: When writing algorithms the best method, I have found, is pretending like you  are writing a detailed procedure to a child. Assume this child knows nothing and you  must explain everything to them. Ex. You are running a hotel. Your job is to greet the guest, ask them how many nights they are staying then charge them.  Step 1: Display a message to the user: “Hello! Welcome to ____ hotel. My  name is Parker.” Then end the line. Step 2: Create a global constant integer called PRICE_PER_NIGHT and set it  equal to 50. Step 3: Display a message to the user: “How many nights are you staying: “ Step 4: Create a local integer variable called nightsStayed and store the user’s  answer in this variable. Step 5: Create an int function called CalculateCost with 1 integer parameter  called nightsStayed (this is separate from the local variable we created but has  the same name so you know where to put it). a. In this function create an int variable called totalCostand set it equal  to the nightsStayed parameter multiplied by the global constant  PRICE_PER_NIGHT.  b. Return totalCost Step 6: Display a message: “The price for nightsStayed(variable) night(s)  stayed is CalculateCost(put in the function).” Step 7: Display message: “Thank you, come again!” Learn to write a better algorithm­­programming­is­an­algorithm­in­programming­definition­ examples­analysis.html Here is a program I made a year ago that has my algorithm and code. Hopefully this  helps you understand programming better. For any terms you don’t understand go to  this site­ and in the search bar type in any term you do not  understand (i.e. float)  /* Program Name: GeometryFun Author: Parker Moore Date Created: 1/20/16 IDE: Visual Studio 2012 Purpose: To find the different calculations of perimeter, area and potentially radius(in the case of a circle) given a user entered whole number */ /* Inputs: Number Entered Constants: PI = 3.1415 Outputs: Perimeter of square Aera of square radius of circle perimeter of circle area of circle ************************************* A square with side length of 7 has a perimeter of 28 has an area of 49 A circle with a diameter of 7 has a radius of 3.5 has a perimeter of 21.9905 has an area of 38.4834 ************************************* Algorithm: Prompt user for number enter number into calculations Find perimeter of square: perimeter = 4 * numberEntered Find area of square: area = numberEntered * numberEntered Find radius of circle: radius = static_cast<float>(numberEntered) / 2 Find perimeter of circle = perimeter2 = 2 * PI * radius Find area of circle = area2 = PI * pow(radius,2) Find perimeter of equilateral triangle = 3 * numberEntered Find area of equilateral triangle = sqrt(3) / 4 * (pow(numberEntered),2) Find the perimeter of a polygon with x sides = numberEntered * numberOfSides Find apothem = numberEntered / (2 * tan(180/numberOfSides)) Find area of a polygon with x sides = (1/2) * perimeter4 * apothem Output data as specified */ // pre-processor directives #include <iostream> //required for cin and cout #include <cmath> #include <string> #include <iomanip> using namespace std; //constants const double PI = 3.1415; void main() { //Variables int numberEntered; int numberOfSides; int perimeter = 0.0; int area = 0; float radius = 0.0; float perimeter2 = 0.0; float area2 = 0.0; float perimeter3 = 0.0; float area3 = 0.0; float perimeter4 = 0.0; float area4 = 0.0; float apothem = 0.0; //Algorithm //prompt user to enter a whole number cout << "Please enter a positive whole number: "; //enter number into program cin >> numberEntered; //prompt user to enter amount of sides for a polygon cout << "Please enter a number of sides: "; //enter number into program cin >> numberOfSides; //Calculations perimeter = 4 * numberEntered; //perimeter of square formula area = pow(numberEntered,2);// area of square formula radius = static_cast<float>(numberEntered) / 2;//circle radius formula perimeter2 = 2 * PI * radius;//circle perimeter formula area2 = PI * pow(radius,2);//circle area perimeter3 = 3 * numberEntered;//tirangle perimeter formula area3 = sqrt(3) / 4 * pow(numberEntered,2);//triangle area formula perimeter4 = numberEntered * numberOfSides;//polygon perimeter formula apothem = numberEntered / 2 * tan(180/numberOfSides);//apothem formula area4 = perimeter4 * apothem / 2;//polygon area formula //Output cout << fixed; cout << "\n A square with a side length of " << numberEntered << endl; cout << "\t has a perimeter of " << perimeter << endl; cout << "\t has an area of " << area << endl; cout << "\n A circle with a diameter of " << numberEntered << endl; cout << "\t has a radius of " << setprecision(3) << radius << endl; cout << "\t has a perimeter of " << setprecision(3) << perimeter2 << endl; cout << "\t has an area of " << setprecision(3) << area2 << endl; cout << "\n An equilateral triangle with side length of " << numberEntered << endl; cout << "\t has a perimeter of " << perimeter3 << endl; cout << "\t has an area of " << setprecision(3) << area3 << endl; cout << "\n A polygon with " << numberOfSides << " sides each " << numberEntered << " in length " << endl; cout << "\t has a perimeter of " << perimeter4 << endl; cout << "\t has an area of " << setprecision(3) << area4 << endl; cin.get();//leaves console open cin.ignore(); }  


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Anthony Lee UC Santa Barbara

"I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.