Monday, September 19, 2016

Programming Assignment 2

Code:

//
//  main.cpp
//  homework2
//
//  Created by Mark Brautigam on 9/18/16.
//  Copyright © 2016 Mark Brautigam. All rights reserved.
//

/*
 Mark Brautigam - ID 123456
 CS 102 - Fall 2016 - Ohlone College
 Sept. 18, 2016
 */

#include <iostream>
#include <math.h>       /* sqrt */
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cout << "Hello, World!" << endl;
    
    cout << "What is your zip code? ";
    string zipcode;
    cin >> zipcode;
    cout << "Your zip code: " << zipcode << endl;
    
    // Arithmetic operations
    cout << "What is the length of side a : ";
    string a;
    cin >> a;
    double aa = atof(a.c_str());
    
    cout << "What is the length of side b : ";
    string b;
    cin >> b;
    double bb = atof(b.c_str());
    
    //     _  /  2   2
    // c =  \/  a + b
   
    double cc = sqrt ((aa * aa) + (bb * bb));
    cout << "The hypotenuse is " << cc << endl;
    
    char c = 320;
    cout << c << endl;
    
    short s = 12345;
    int i = 4321;
    int pi = 3.14;
    cout << pi << endl;
    
    return 0;
}

/*
 Hello, World!
 What is your zip code? asdf
 Your zip code: asdf
 What is the length of side a : 4
 What is the length of side b : 3
 The hypotenuse is 5
 @
 3
 Program ended with exit code: 0
 */




No comments:

Post a Comment