Sunday, February 22, 2015

Getting started

What is the output of string INSTITUTION = "Richland \rCollege"; ?  There is also a major implementation problem with this code that you should be able to find it easy.

//Project 0: Hello World
//Revision: 1.0
//Date: 08/15/2011
//Description: Chapter 2 Summary

#include <iostream>
#include <string>
#include <math.h>
#include"header.h"

using namespace std;
using namespace richland;

int main(){

    string INSTITUTION = "Richland \rCollege";
    cout << INSTITUTION << endl;

    float PI = 3.14E0;
    cout << PI << endl;

    int value = -200;

    cin >> celsius>>value;

    fahrenheit = (float)((celsius)*(9 / 5) + 32);

    cout << fahrenheit<< endl;

    float ans = (fahrenheit - 32)*(5 / 9);

    cout << ans << endl;

    char ch = 'A';
    cout << "The \"value\" is: " <<ch<< endl;
    cout << "The value is: " << ch+1 << endl;
    cout << "The value is: " << static_cast<char>(ch+1)<< endl;

    string hello = "Hello";

    hello[3] = 'p';

    cout << "The \nstring \tis: " << hello << endl;

    return 0;
}

Pattern recognition and simple applications

You can use system("pause"); to call the pause utility in Windows systems to pause your program execution, but not many students realize that you can call other applications from C++ using this system call and have a useful application quickly.

Like translating with Google translate only requires you to look at the URL when you translate something and recognize the pattern in the URL.  You should see that you format the URL string as /#source_language/destination_language/text_to_translate.

Thus, in this example you are translating from German to English and launch Firefox to display the results.


//Required libraries
‪#‎include‬<iostream> //cin, cout, endl
#include<string> //string

//Namespace specified to avoid using std:: with cin, cout, endl, ...
using namespace std;

int main(int argc, char* argv[]){
      string program = "\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\"  
                                  https://translate.google.com/#de/en/ich%20bin%20ein%20kinder";
      char* prog;
      prog = &program[0];
      system(prog);                         //The magic happens here
      return 0;                                 //return integer data type to OS to indicate errorlevel
}


Look up information about an IP address.

// exceptions
#include <iostream>
#include <string>


using namespace std;
void printMe(string url){
    cout << url << endl;
    system(&url[0]);
}

int main() {
    string url = "start \"C:\\Program\ Files\ \(x86\)\\Google\\Chrome\\Application\\Chrome.exe\"\ \"http\://144\.162\.1\.180\.ipaddress\.com/#reverseip\"";
    printMe(url);

    return 0;
}


Map a location using Google maps and the location's GPS coordinates.

#include <iostream>
using namespace std;

int main()
{
    //Call Chrome browser and open a GPS coordinate
    system("\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" HTTP://MAPS.GOOGLE.COM/?q=32.921763,-96.729206");
       
    return 0;
}

Experiment with other useful application of this simple system call and go beyond what you use it for in standard applications.  Don't be afraid of creating something new and useful even if it looks simple.