cs31 lecture 2

X 95 of the work precisely define the problem and 95

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: ogram working for a hybrid car program x It is actually implemented in most cars! x 95% of the work: precisely define the problem, and 95% understand how to deal with any possible inputs understand x Work left: use a programming language to translate our Work algorithm into an actual program that can be compiled and executed by the car’s computer executed 25 A brief of C++ Algorithm MPG: IInput: nput: • m: number of miles since last refuel • g: number of gallons consumed since last refuel Output: • mpg: miles per gallon achieved 1.mpg := m / g 2.return mpg return 26 A brief of C++ float MPG(float m, float g) { float mpg = m / g; float return mpg; return } int main() { float mpg = MPG(42, 10); float std::cout << “My mpg: “ << mpg << std::endl; std::cout } 27 C++ basics float MPG(float m, float g) { float mpg = m / g; float return mpg; return } xAll variables are typed A type: a definition of the ‘kind’ of data the variable holds Typical (scalar) types: Typical • int (for numbers which are signed integers) • float (for arbitrary numbers) 28...
View Full Document

This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Ask a homework question - tutors are online