Monday, October 17, 2016

October 17 PowerPoints and Midterm exam

The midterm exam is posted on Canvas.

October 17 Midterm Review:

Code: 
//
//  main.cpp
//  Oct17
//
//  Created by Mark Brautigam on 10/17/16.
//  Copyright © 2016 Mark Brautigam. All rights reserved.
//

#include <iostream>
#include <string> 
using namespace std;

// ----------------------------------------------------
bool isSquareLetter (char c) {
// ----------------------------------------------------
    
    char u = toupper(c);
    /*
    if (u == 'A' || u == 'E' || u == 'F' ||
        u == 'H' || u == 'I' || u == 'K' ||
        u == 'L' || u == 'M' || u == 'N' ||
        u == 'T' || u == 'V' || u == 'W' ||
        u == 'X' || u == 'Y' || u == 'Z')
    */
    string legalChars = "AEFHIKLMNTVWXYZ";
    return legalChars.find(u) != string::npos;
    /*
    if (legalChars.find(u) != string::npos)
        return true;
    else
        return false;
     */
    // return true;
}


// ----------------------------------------------------
string squareLetters (string s) {
// ----------------------------------------------------
    
    string newString = "";
    
    int i = 0;
    while ( i<s.length()) {
        if (isSquareLetter(s[i])) {
            newString += toupper(s[i]);
        }
        i++;
    }
    return newString;
}

// ----------------------------------------------------
string swap3 (string s) {
// ----------------------------------------------------
    return s.substr(3) + s.substr(0,3);
}

// ----------------------------------------------------
string fixName (string name) {
// ----------------------------------------------------
    long comma = name.find(',');
    return name.substr(comma+1) + " " + name.substr(0,comma);
    return "notyet";
}


/*
// ----------------------------------------------------
string reverse (string s) {
// ----------------------------------------------------
    int i = s.length()-1;
    while (i >= 0) {
        
    }
}
 */

// ----------------------------------------------------
int main(int argc, const char * argv[]) {
// ----------------------------------------------------

    string userInput = "";
    while (userInput != "done") {
        
        cout << "Type a number or \"done\" when finished: ";
        cin >> userInput;
        if (userInput == "done")
            break;
        
        cout << squareLetters (userInput) << endl;
        cout << swap3 (userInput) << endl;
        cout << fixName (userInput) << endl;
        
        // cout << "You said number " << atof(userInput.c_str()) << endl;
    }
    
    
    return 0;
}



No comments:

Post a Comment