Friday, April 22, 2011

4/somethig

So im still working on the project I was before, below is what I have at the moment:


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  
  
    int num1, num2, num3;
    int a, b, c;
    int greater;
  
  
  
    cout << "input your first number: ";
    cin >> num1;
    cout << endl;
  
    cout << "input your second number: ";
    cin >> num2;
    cout << endl;
  
    cout << "input your third number: ";
    cin >> num3;
    cout << endl;
  

  
  
  
    if (num1 > num2 && num3)
     cout << num1 << endl;
    
    
      
    else if (num2 > num3)
         cout << num2 << endl;
  
    else if (num2 > num1)
         cout << num2 << endl;
  
    else if (num3 > num1)
         cout << num3 << endl;
        
    else if (num3 > num2)
         cout << num3 << endl;
      
      
      
          
    if (num2 > num1 && num3)
     cout << num2 << endl;
      
  
        else if (num3 > num2)
         cout << num3 << endl;
        
    else if (num3 > num1)
         cout << num3 << endl;

  
    else if (num1 > num3)
         cout << num1 << endl;
        
    else if (num1 > num2)
         cout << num1 << endl;

        
        
    if (num3 > num1 && num2)
     cout << num3 << endl;
    
         else if (num2 > num1)
         cout << num2 << endl;
        
    else if (num2 > num3)
         cout << num2 << endl;
  
    else if (num1 > num2)
         cout << num1 << endl;
        
    else if (num1 > num3)
         cout << num1 << endl;
  


  
    system("PAUSE");
    return EXIT_SUCCESS;
}

the issue im having now is that lets say that num1 is smaller than num2 but not num3, the program sees that num1 is not greater than num2 and num3 and prints num2 or num3, whatever comes first in the program. It does this for each block of code.


What I really wanted to do is use >! inside an IF statement: if (num1 > num2 && num1 <  num3)
but it doesn't seem to work like that =( 

im proboly going to work on other stuff tomorrow (business communications) since it needs to be in by Monday and other than this one program im a week ahead in programming 

Thursday, April 21, 2011

4/21

So Ive been working on the following assignment the last 1-2 weeks:

Write a C++ program that prompts the user to input three numbers. 
The program should then output the numbers in ascending order.

Ive been having a lot of problems with it. After I find the first highest number I have to then find the number below that, which has been the main issue.


Ive tried redefining the variable used for the first number and then asking if this or that number is <= to it.


I think I'm getting very close to figuring it out at the moment.





#include <cstdlib>
#include <iostream>


using namespace std;


int main(int argc, char *argv[])
{
    
    
    int num1, num2, num3;
    int a, b, c;
    int greater;
    
    
    a = num1;
    b = num2;
    c = num3;
    
    
    
    cout << "input your first number: ";
    cin >> num1;
    cout << endl;
    
    cout << "input your second number: ";
    cin >> num2;
    cout << endl;
    
    cout << "input your third number: ";
    cin >> num3;
    cout << endl;
    
    if (num1 > num2 && num3)
     cout << num1;
     cout << endl;
       
       
       else if (num2 > num1 && num3)
        cout << num2;
        cout << endl;
            
            
       else(num3 > num1 && num2)
            cout << num3;
            cout << endl;
            
       if (num3 > num1 && num2)
          cout << num3;
          cout << endl;
          
          else
          cout << num2;
          cout endl;
            


    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;


}






The issue I'm having now is that the compiler I'm using is saying that there is a syntax error before every "else" statement (end o line)

Tuesday, April 12, 2011

4/12

made a few programs....
1. Write C++ statements for the following:
a. Reading 1 line of input and storing the result in the variable myVariable 
b. The square root of x - y. 
c. The value of 3.62 raised to the 3rd power.
d. The value of 81 raised to the .24 power.
e.  Ignoring the first 40 characters or all characters until the character 'B' is found, whichever comes first. 
f. Displaying "Hello World" to the screen. 


#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[])
{
    ifstream inData;
    ofstream outData;

    string variable2;
    int myvariable;
    int variable;
  
    inData.open("test.dat");
    outData.open("testavg.out");
  
    outData << fixed << showpoint;
    outData << setprecision(2);
  
    outData << "data" << endl;
  
  
    inData >> variable2;
    outData << "student name: " << variable;
  

    
  
    inData.close();
    outData.close();
  
  
  
    cout << "input variable: ";
    cin >> myvariable;
  
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}

Friday, April 8, 2011

week of...4/3

made some C++ programs(very simple ones)


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  
    string name;
    string color;
    int age;
  
    cout << "what is your name: \n";
    cin >> name;
    cout << endl;
      
    cout << "what is your favorite color: \n";
    cin >> color;
    cout << endl;
  
    cout << "oh..and what is your age: \n";
    cin >> age;
    cout << endl;
  
    cout << "name: " << name << endl;
    cout << "color: " << color << endl;
    cout << "age: " << age << endl;
  
    system("PAUSE");
    return EXIT_SUCCESS;
}





#include <iostream>

using namespace std;

    const int SECERT_NUM = 11213;
    const int PAY_RATE = 18.35;
    

int main()
{


    int one, two, SECERET_NUM;
    int hours = SECERT_NUM + 3;
    double first, second, three;
  
    string paycheck;
  
    one = 18;
    two = 11;
    first = 25;
    three = 3;
    second = first * three;
    paycheck = hours * PAY_RATE;
  

    cout << first << " " << second << SECERET_NUM << endl;
  
    cout << "wages = " << second << endl;
  
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}


note
above should have double for the "const"



The C programming language is generally considered a structured programming language, while C++ is object-oriented. What enhancements were made to C++ to make it object-oriented? What types of applications are better suited to structured programming? object-oriented programming? 





The difference(s) is Polymorphism: Instead of writing logic as “if this do XYZ; if that do ABC” we define the shape and it draws itself


Encapsulation: it’s the ability to group/bundle data and code in one place to hide from the outside world 


Inheritance: this gives you the ability to extend objects/structure that are already in place.
Say you have Cup object. In structured code, you can have it be either empty or full.
In OOD you can have it be full, empty, (replacing full with )pop, water, cool aid, anything you want.


It’s really up to the programmer what they want to do, you can do almost anything in structured that you can in OOD, but OOD makes it so much easier because of the things that were implemented(see above)








after thinking about it for a bit more, I have to agree with one of the other students, things such as payroll would be better for constructed and games would be better for OOD

reason
if you have a payroll, you have don't have any or very little objects, and because of that you dont have to add any/few functions for them to interact with other objects if there are any
in gmaes, you have so many things that need to be defined, user characters, fireballs, monsters, user to user actions. It would take you a very long time to do in constructed


Monday, April 4, 2011

4/5

started new semester today, only IT class I have is programming 1

I'm more than likely going to have to put python on hold for a bit to get through this semester.
Programming 1 seems a bit more demanding than the previous classes so far.


week one
assignment: to come(basically write a program in c++)

Saturday, April 2, 2011

4/2

"working with errors" in python


worked with the TRY: and EXCEPT: commands vs adding extra code to handle errors.

long story: try and except are better. You can handle unexpected errors that may come up and you dont have to add extra code for every error in your code, which makes your code harder to read and even harder to fix if someone else were to read it.