Monday, May 16, 2011

Challenge Lesson 8 Source Code

List of videos Challenge 1
First Challenge NOTE: for a fast copy, follow these steps in order:
  1. Click anywhere in the text box below (result will be a blinking vertical line in the text box
  2. Hit ctrl + A on the key board (the "ctrl + A" means hit Ctrl and A at the same time) (The result should be that all the text inside the text box lights up in blue)
  3. Hit Ctrl + C (Nothing significantly happens that is visible) and now its copied to the clipboard and your ready to paste it anywhere you wish
Solution 1
Solution 2

24 comments:

  1. Ahh, it seems I took alot of unnecessary steps. I wonder if this pastes right--



    #include
    using namespace std;

    int main()
    {

    double r1 = 1;
    double r2 = 1;
    double t1 = 1;
    double t2 = 1;


    cout << "Type in a length of a rectangle: ";
    cin >> r1;
    cout << "Type in the height of a rectangle: ";
    cin >> r2;
    cout << "Type in a length of a triangle: ";
    cin >> t1;
    cout << "Type in a height of a triangle: ";
    cin >> t2;

    double ar = r1 * r2;
    double at = (t1 * t2) / 2;

    cout << endl << "Area of Rectangle: " << r1 * r2 << endl
    << "Area of Triangle: " << (t1 * t2) / 2 << endl
    << "Sum of Areas: " << ar + at << endl;





    system("pause");
    return 0;
    }

    ReplyDelete
  2. It works, but should've used double.



    #include
    using namespace std;

    int main()
    {
    int a,b,c,d;
    cout << "Enter the length of the rectangle: " ;
    cin >> a;
    cout << endl;
    cout << "Enter the width of the rectangle: " ;
    cin >> b;
    cout << endl;
    cout << "Enter the length of the triangle: " ;
    cin >> c;
    cout << endl;
    cout << "Enter the width of the triangle: " ;
    cin >> d;
    cout << endl << endl;

    cout << "The area of the rectangle is: " << a*b << endl;
    cout << "The area of the triangle is: " << (c*d)/2 << endl;
    cout << "The total area is: " << (a*b)+((c*2)/2) << endl ;


    system("pause") ;
    return 0;
    }

    ReplyDelete
  3. My code works, but whenever I try to enter a non-integer value, it will output everything else at once. Please help me. Thank you so much for your lessons and your help.

    #include
    using namespace std;

    int main()
    {
    int rectangle_length = 0;
    int rectangle_height = 0;
    int triangle_length = 0;
    int triangle_height = 0;

    cout << "Type in a length of a rectangle: ";

    cin >> rectangle_length;

    cout << "Type in a height of a rectangle: ";

    cin >> rectangle_height;

    cout << "Type in a length of a triangle: ";

    cin >> triangle_length;

    cout << "Type in a height of a triangle: ";

    cin >> triangle_height;

    cout << "Area of Rectangle: " << rectangle_length * rectangle_height << endl;
    cout << "Area of Triangle: " << 0.5 * triangle_length * triangle_height << endl;
    cout << "Sum of Area: " << rectangle_length * rectangle_height + 0.5 * triangle_length * triangle_height << endl;

    system ("pause");
    return 0;
    }

    ReplyDelete
    Replies
    1. If you change the variable from an "int" to a "float" or "double" it will take care of your problem. The float and double allow you to use decimals.

      Delete
  4. Think I got so far, a little stressful at first lol.


    #include
    using namespace std;

    int main()
    {
    int LT =0;
    int HT =0;
    int LR =0;
    int HR =0;

    cout << "Type in a length of a Triangle: ";
    cin >> LT;
    cout << "Type in a hight of a Triangle: ";
    cin >> HT;
    LT,HT = LT*HT/2;

    cout << "Type a length of a Rectangle: ";
    cin >> LR;
    cout << "Type in a hight of a Rectangle: ";
    cin >> HR;
    LR,HR = LR*HR;
    cout << endl;

    cout << "The area of a Triangle is: "<< LT*HT/2 <<endl;
    cout << "The area of a Rectangle is: "<< LR*HR <<endl;
    cout << "The Sum of the area is: "<< LT*HT/2 + LR*HR <<endl;



    system ("pause");
    return 0;
    }

    ReplyDelete
  5. Fixed my HUGE mess up lol from my above post. Added a few things and I went through and fixed them.

    #include
    using namespace std;

    int main()
    {
    double LT =0;
    double HT =0;
    double LR =0;
    double HR =0;

    cout << "Type in a length of a Triangle: ";
    cin >> LT;
    cout << "Type in a hight of a Triangle: ";
    cin >> HT;
    LT*HT/2;

    cout << "Type a length of a Rectangle: ";
    cin >> LR;
    cout << "Type in a hight of a Rectangle: ";
    cin >> HR;
    LR*HR;
    cout << endl;

    cout << "The area of a Triangle is: "<< LT*HT/2 <<endl;
    cout << "The area of a Rectangle is: "<< (LR*HR) <<endl;
    cout << "The Sum of the area is: "<< LT*HT/2 + LR*HR <<endl;



    system ("pause");
    return 0;

    ReplyDelete
  6. #include
    using namespace std;
    int main()
    { double a,b,c,d;
    cout <<"Please insert the value of the base of your rectangle: ";
    cin >> a;
    cout <<"Please insert the value of the height of your rectangle: ";
    cin >> b;
    cout <<"Please insert the value of the base of your triangle: ";
    cin >> c;
    cout <<"Please insert the value of the height of your triangle: ";
    cin >> d;
    cout <<"The area of your rectangle is: " << a*b <a*b)
    cout<<"Your triangle area is bigger than the area of your rectangle because "< " << a*b<<endl;
    if(c*d/2==a*b)
    cout<<"Both of your areas are the same size because "<<c*d/2 << " = " << a*b<<endl;
    system("pause");
    return 0;




    Ignore the 'if' staff.

    ReplyDelete
  7. #include
    using namespace std;
    int main()
    { double a,b,c,d;
    cout <<"Please insert the value of the base of your rectangle: ";
    cin >> a;
    cout <<"Please insert the value of the height of your rectangle: ";
    cin >> b;
    cout <<"Please insert the value of the base of your triangle: ";
    cin >> c;
    cout <<"Please insert the value of the height of your triangle: ";
    cin >> d;
    cout <<"The area of your rectangle is: " << a*b <a*b)
    cout<<"Your triangle area is bigger than the area of your rectangle because "< " << a*b<<endl;
    if(c*d/2==a*b)
    cout<<"Both of your areas are the same size because "<<c*d/2 << " = " << a*b<<endl;
    system("pause");
    return 0;

    ReplyDelete
  8. I put the area results for the rectangle, triangle, and total area into variables, in case I needed to use them elsewhere someday. True, it's a simple program now, but what if it were to develop further down the line?

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. #include
    using namespace std;

    int main()
    {
    float baset,heightt,lengthr,heightr;
    cout<<"Type in the base length of the triangle in cm: ";
    cin>>baset;
    cout<<"Type in the height of the triangle in cm: ";
    cin>>heightt;
    cout<<"Type in the length of the rectangle in cm: ";
    cin>>lengthr;
    cout<<"Type in the height of the rectangle in cm: ";
    cin>>heightr;
    cout<<endl<<endl<<endl;
    cout<<"Area of triangle is "<<baset*heightt/2<<" square cm."<<endl;
    cout<<"Area of rectangle is "<<lengthr*heightr<<" square cm."<<endl;
    cout<<"Sum of area is "<<baset*heightt/2+lengthr*heightr<<" square cm."<<endl<<endl;
    system("pause");
    return 0;
    }
    This is what I came up with.
    I measure in cm , I`m from europe.

    ReplyDelete
  12. This is what i ended up with..
    I think my c++ logic is alright?
    Notice I'm experienced with vb =P.

    #include
    using namespace std;

    int main()
    {
    float length_rectangle = 0;
    cout << "Type in a length of a rectangle: ";
    cin >> length_rectangle;
    float height_rectangle = 0;
    cout << "Type in a height of a rectangle: ";
    cin >> height_rectangle;

    float length_triangle = 0;
    cout << "Type in a length of a triangle: ";
    cin >> length_triangle;
    float height_triangle = 0;
    cout << "Type in a height of a triangle: ";
    cin >> height_triangle;

    cout << endl;

    float total_rectangle = length_rectangle * height_rectangle;
    cout << "Area of Rectangle: " << total_rectangle << endl;

    float total_triangle = length_triangle * height_triangle / 2;
    cout << "Area of Triangle: " << total_triangle << endl;

    float total_area = total_rectangle + total_triangle;
    cout << "Sum of area: " << total_area << endl;

    system("pause");
    return 0;
    }

    ReplyDelete
  13. #include
    using namespace std;

    int main()
    {
    int R1,R2,T1,T2;
    cout << "Type in a lenght of a rectangle: ";
    cin >> R1;
    cout << "Type in a hight of a rectangle: ";
    cin >> R2;
    cout << "Type in a lenght of a triangle: ";
    cin >> T1;
    cout << "Type in a hight of a triangle: ";
    cin >> T2;

    int R3 = R1*R2, T3 = T1*T2/2, RT = R3+T3;

    cout << "Area of Rectangle: " << R3 << endl;
    cout << "Area of Triangle: " << T3 << endl;
    cout << "Sum of area: " << RT << endl;
    system("pause");
    return 0;
    }

    ReplyDelete
  14. I realized my mistake using int instead of double. int couldn't handle 2.178.

    You are indeed a great teather, thank you sir for the time and effort you made in this.

    #include
    using namespace std;

    int main()
    {
    double R1=0,R2=0,T1=0,T2=0;
    cout << "Type in a lenght of a rectangle: ";
    cin >> R1;
    cout << "Type in a hight of a rectangle: ";
    cin >> R2;
    cout << "Type in a lenght of a triangle: ";
    cin >> T1;
    cout << "Type in a hight of a triangle: ";
    cin >> T2;

    double R3 = R1*R2, T3 = T1*T2/2, RT = R3+T3;

    cout << "Area of Rectangle: " << R3 << endl;
    cout << "Area of Triangle: " << T3 << endl;
    cout << "Sum of area: " << RT << endl;
    system("pause");
    return 0;
    }

    ReplyDelete
  15. #include
    using namespace std;

    int main()
    {
    double x=0;
    double y=0;
    double a=0;
    double b=0;

    cout << "Enter the length of a rectangle: ";
    cin >> x;
    cout << endl;
    cout << "Enter the height of a rectangle: ";
    cin >> y;
    cout << endl;
    cout << "Enter the length of a triangle: ";
    cin >> a;
    cout << endl;
    cout << "Enter the height of a triangle: ";
    cin >> b;
    cout << endl;
    cout << endl;
    cout << "Area of rectangle: " << x * y;
    cout << endl;
    cout << "Area of triangle: " << a * b * 0.5;
    cout << endl;
    cout << "Sum of area: " << x * y + a * b * 0.5;
    cout << endl;
    cout << endl;

    system("pause");
    return 0;
    }

    ReplyDelete
  16. I'm gone to tell my little brother, that he should also pay a visit this webpage on regular basis to take updated from most recent news.

    Feel free to surf to my weblog: how to make money on youtube

    ReplyDelete






  17. this is where i got to not sure if its right or wrong, im not the best at maths aswell so lol


    #include
    using namespace std;

    int main()
    {
    float x,s,q,z;

    cout << "Enter the hight of the triangle ";
    cin >> x;
    cout << "Enter the length of the triangle ";
    cin >> q;
    cout << "Enter the hight of the rectangle ";
    cin >> s;
    cout << "Enter the length of the rectangle ";
    cin >> z;
    cout << endl;
    cout << "The area of the triangle is " << q * x << endl;
    cout << "The area of the rectangle is " << s * z << endl;
    cout << "The total of the sum is" << q * x + s * x << endl;



    system ("pause");
    return 0;

    ReplyDelete
  18. #include
    using namespace std;

    int main()
    {
    double lp;
    double hp;
    double lt;
    double ht;
    double ariaP;
    double ariaT;

    cout << "Introduceti lungimea laturii unui patrulater: ";
    cin >> lp;
    cout << "Introduceti inaltimea laturii unui patrulater: ";
    cin >> hp;

    cout << "Introduceti lungimea laturii unui triunghi: ";
    cin >> lt;
    cout << "Introduceti inaltimea laturii unui triunghi: ";
    cin >> ht;
    cout << endl;
    ariaP = lp * hp;
    ariaT = (lt * ht)/2;

    cout << "Aria unui patrulater este: " << ariaP << endl;
    cout << "Arian unui triunghi este: " << ariaT <<endl;
    cout << "Suma ariilor este: " << ariaP + ariaT << endl;
    system("pause");
    return 0;
    }

    ReplyDelete
  19. #include
    using namespace std;

    int main()
    {
    int length = 1;
    int height = 1;
    int base = 1;
    int theight = 1;
    cout << "Type in the length of a rectangle ";
    cin >> length;
    cout << "Type in the height of a rectangle ";
    cin >> height;
    cout << "The length of a rectangle is " << length << endl;
    cout << "The height of a rectangle is " << height << endl;
    cout << "The area of a rectangle is " << length*height << endl;
    cout << " Type in the base of a triangle ";
    cin >> base;
    cout << " Type in the height of a triangle ";
    cin >> theight;
    cout << " The base of a triangle is " << base << endl;
    cout << " The height of a triangle is " << theight << endl;
    cout << " The area of a triangle is " << base*theight/2 << endl;
    system ("pause");
    return 0;
    Just trying to learn programming in my spare time as a web development student. Am I crazy?

    ReplyDelete
  20. #include
    using namespace std;
    int main()
    {
    double a ,b,c,d,x,y,z;
    cout<<"Type in a length of a rectangle:";
    cin>>a;
    cout<<"Type in a heigth of a rectangle:";
    cin>>b;
    cout<<"Type in a length of a triangle:";
    cin>>c;
    cout<<"Type in a heigth of a triangle:";
    cin>>d;
    cout<<endl;
    cout<<endl;

    x =a * b;
    y =c * d / 2;
    z =x + y;
    cout<<"Area of Rectangle: "<<x<<endl;
    cout<<"Area of Triangle: "<<y<<endl;
    cout<<"Sum of Areas: "<<z<<endl;
    system("pause");
    return 0;
    }

    ReplyDelete
    Replies
    1. You are logic and appraoch is much difffernt then every one great :D

      Delete
  21. I think I took too much steps..
    #include
    using namespace std;
    int main()
    {
    double Rx,Ry,Tx,Ty;
    cout << "Type in a length of a rectangle: ";
    cin >> Rx;
    cout << "Type in a hight of a rectangle: ";
    cin >> Ry;
    double Ra = Rx*Ry;
    cout << "Type in a length of a triangle: ";
    cin >> Tx;
    cout << "type in a hight pf a triangle: ";
    cin >> Ty;
    double Ta = 0.5*(Tx*Ty);
    cout << endl << "Area of the rectangle: " << Ra
    << endl << "Area of the Triangle: " << Ta << endl;
    double S = Ra + Ta;
    cout << "The sum of the area: " << S << endl;
    system("pause");
    }

    ReplyDelete