lecture2slides

lecture2slides - Agenda 1. Questions about project #1 2....

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Agenda 1. Questions about project #1 2. Project #2 information 3. Programming challenge 4. strings 5. Control structures: if/else, conditional-operator, while loops 6. Counter-controlled repetition 7. Sentinel-controlled repetition Programming Challenges 1. Write a program that inputs 3 numbers and prints out the numbers from smallest to largest 2. What does the following program print? main() { int usc = 0, ucla = 100; if (ucla = usc) std::cout << yeah right.; if (ucla > usc) std::cout << gogogo bruins!; } 3. Write a program that inputs a number of cents and prints out the minimum number of quarters, dimes, nickels and pennies needed to make up the amount. strings C++ provides a new data type like int or double, but it holds a string of letters. To use this data type, you must include a new header file: #include <string> A string can hold 0 or more characters. When you declare a new string variable, it is guaranteed to be empty by default. THIS IS NOT TRUE FOR OTHER TYPES LIKE int! A string is a C++ object that was designed for us to make it easy to use strings. // this program shows how to use the // string variable type #include <iostream> #include <string> using namespace std; int main(void) { string a, b = "Hello"; cout << "Enter your name: "; cin >> a; cout << b << " " << a << endl; if (a == "carey") cout << "what a geek!\n"; return(0); } Questions: 1. What happens if the user types narey catchenberg (no quotes) 2. What happens if the user types Carey (with a capital C) // this program shows how to // do more with strings #include <iostream> #include <string> using namespace std; int main(void) { string first, last, b = "Hello"; cout << "Enter first/last names: "; cin >> first >> last; if (first == "carey") first = first + "boberry"; if (first == "george") first = "curious " + first; cout << b << " " << first << " " << last << endl; return(0); } Control Structures Q: Whats an algorithm ? A: An algorithm is a set of instructions/steps that solve a particular problem. Algorithms Continued Q: What is pseudocode A: Pseudocode is an informal English- like language used to describe algorithms. Pseudocode is for humans only, there is no pseudocode compiler....
View Full Document

This note was uploaded on 10/08/2011 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Page1 / 25

lecture2slides - Agenda 1. Questions about project #1 2....

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online