{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lab 9 work

# lab 9 work - ME 218(17795 Alan Shu-Ming Kwok(sk25784 Lab 9...

This preview shows pages 1–3. Sign up to view the full content.

ME 218 (17795) Alan Shu-Ming Kwok (sk25784) Lab 9 1. Write a simple program that performs the following pseudo-code: #include <iostream> #include <stdio.h> #include <math.h> using namespace std; #define PI 3.141592654 bool zipvalid( int zip) { int zip_prefix = 0; int exclusion[] = {0, 1, 2, 3, 4, 99, 213, 269, 343, 345, 348, 353, 419, 428, 429, 517, 518, 519, 529, 533, 536, 552, 568, 578, 579, 589, 621, 632, 642, 643, 659, 663, 682, 694, 695, 696, 697, 698, 699, 702, 709, 715, 732, 742, 771, 817, 818, 819, 839, 848, 849, 854, 858, 861, 862, 866, 867, 868, 869, 876, 886, 887, 888, 892, 896, 899, 909, 929, 987 }; zip_prefix = zip/ 100; for ( int i = 0; i<= 68; i++) { if (zip_prefix == exclusion[i]) { cout<< " Invalid Zip Code." << endl; return false ;} } if (zip_prefix < 0 || zip_prefix > 999) { cout<< " Invalid Zip Code." << endl; return false ;} cout << " Zip code is valid" <<endl; return true ; } double h( int zip) { int middle_digit = (zip/100) %10; if (middle_digit < 5) return 0.05; else if (middle_digit < 6) return 0.1; else return 0.2; } int panel( int zip) { int first_digit = zip/10000; int second_digit = (zip/1000) % 10; if (first_digit < second_digit) return 14; else if (first_digit == second_digit) return 16; else return 20; } int function_number( int zip) { int second_to_last_digit = ( zip%100 ) / 10; if (second_to_last_digit > 5) return 1; else if (second_to_last_digit >4)

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

View Full Document
ME 218 (17795) Alan Shu-Ming Kwok (sk25784) Lab 9 return 2; else return 3; } double
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}