Give Me C++ HomeWork Please :)

  • Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
Yo!
i was wondering if anyone could give me an assignment to do i'm kinda stumped
on what i should work on next.....

to show some examples of what i've done so far:

simple interest calculator this one i made because i had to calculate a few different loans to choose from :p
Code:
//by: falidell
#include <iostream>
#include <iomanip>

int main()
{
     using namespace std;
     long double interestp;
     long double amount;
     long double time;
     long double interestm;
     long double interestt;
     long double totalm;
     long double total;
     char yn('y');
     do{
          cout << "Loan Amount : $";
          cin >> amount;
          cout << endl;
          
          cout << "loan Time (months) :";
          cin >> time;
          cout << endl;
          
          cout << "interest rate percent: ";
          cin >> interestp;
          cout << endl;
          
          interestm = (amount/time)*(interestp/100);
          interestt = (amount*(interestp/100));
          totalm = (amount/time)+interestm;
          total = amount+interestt;
          
          cout << "Per Month:" << endl;
          cout << "   Interest: $" << setprecision (5) << interestm << endl;
          cout << "   Payments: $" << setprecision (5) << totalm << endl;
          cout << endl;
          cout << "Total:" << endl;
          cout << "   Interest: $" << setprecision (5) << interestt << endl;
          cout << "   Due: $" << setprecision (5) << total << endl;
          
          cout << "another loan? (y/n)  :";
          cin >> yn;
          cout << endl << endl << endl << endl;
          }while(yn=='y' || yn=='Y');
          
          return 0;


}

and this one is so i can see how much space i have left on my drive
Code:
// left over drive room
// i'm lazy so i made this HAHA
//by : falidell

//Includes!!!!!!!!!!!!!!
#include <iostream>
#include <iomanip>

//Useings and Global Variables!!!!!!
using namespace std;

//Actuall Work stuffs
void PercentUF(long double U, long double M)//Calculate free and used percentages
{
     long double PU;
     long double PF;
     PU = (U/M)*100;
     PF = 100-PU;
     cout << endl;
     cout << setprecision (4) << PU << "% Used";
     cout << endl;
     cout << setprecision (4)<<  PF << "% Free";
     cout << endl;
     }
     
     
void GLOS(long double Used, long double Max , double Per)//get left over space
{
     long double Have;
     long double Space;
     double Perc;
     
     Perc = Per/100;
     Space = (Max*Perc);
     if(Used >= Space)
     {
             Have = Used - Space;
             cout << endl << "you have no room!!!!!!";
             cout << endl;
             cout << "Get Rid of " << setprecision (8) << Have;
             cout << " gigs to get back to the "<<Per<<"% range";
             cout << endl;
             cout << endl;
             cout << endl;
             cout << endl;
     }
     else
     {
         Have = Space-Used;
         cout << "you Have " << setprecision (8) << Have << " gigs left";
         cout << endl;
      
     }
}

int main()
{
       long double U;
       long double M;
       double P;
       int I(1);
       do {
       top: // YES I KNOW i shouldn't use goto statements and such but i
            //couldn't think of any other way to do this
       system("cls");
       cout <<"whats your Desired drive Use percent limit (1-100)?:      ";
       cin >>P;
       if (P < 1 || P > 100)
       {
             cout << endl <<" that is not in the 1-100 range!!!!!";
             cout << endl;
             system("pause");
             goto top; 
       }
       cout <<endl<<"Whats the Max drive Cap:   ";
       cin >>M;
       cout << endl << "how much is used?    ";
       cin >>U;
       
       system("cls");
       GLOS(U,M,P);
       PercentUF(U,M);
       
       
       cout << endl;
       cout << endl;
       cout << "Again? (1/0):  ";
       cin >> I;
       } while ( I == 1);
       return 0;

}


i can also do static and dynamic arrays and i've havn't even looked at how to make a windows API yet :/ so can you guys help me out by giveing me a program to make?
 
Last edited:

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
openCL? hmmmm never heard of it before i'll see what i can do and thankyou for the assignment =D

btw whats optical tracking

in my mind it's tracking where your eyes are looking kind of like the software used in the apache helicopter for the gun on the nose

but i think your talking about a program that tracks where the mouse is?????? x/y coords?
 
Last edited:

Peter.Steele

FNG / Fresh Meat
Sep 6, 2006
2,128
779
0
Chambers of the Grand Council
openCL? hmmmm never heard of it before i'll see what i can do and thankyou for the assignment =D

btw whats optical tracking

in my mind it's tracking where your eyes are looking kind of like the software used in the apache helicopter for the gun on the nose

but i think your talking about a program that tracks where the mouse is?????? x/y coords?



No, more like camera control for a sentry gun or optical guided missile.


Camera sees an object, identifies it as a valid target (by whatever criteria, I suggest color / size and motion: for instance, a ping-pong ball thrown across a webcam's field of view), and the computer tracks the object.

Most often this will take the visual form of putting a box around the target that follows it around, until it either leaves the field of view (either through motion or through camera-carrying vehicle impacting the target), or through the target ceasing to be a valid target (as in a gunfire control system - once the target goes away, it is no longer a valid target).

Practical applications ... well, sentry guns, guided missiles, operation of PTZ cameras to monitor home / office / backyard / whatever ...

Ideally, a sentry gun that can distinguish between MY cat and all the OTHER cats and the possums in the neighborhood, and nail every other cat and the possums with either airsoft or paintballs.
 

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
No, more like camera control for a sentry gun or optical guided missile.


Camera sees an object, identifies it as a valid target (by whatever criteria, I suggest color / size and motion: for instance, a ping-pong ball thrown across a webcam's field of view), and the computer tracks the object.

Most often this will take the visual form of putting a box around the target that follows it around, until it either leaves the field of view (either through motion or through camera-carrying vehicle impacting the target), or through the target ceasing to be a valid target (as in a gunfire control system - once the target goes away, it is no longer a valid target).

Practical applications ... well, sentry guns, guided missiles, operation of PTZ cameras to monitor home / office / backyard / whatever ...

Ideally, a sentry gun that can distinguish between MY cat and all the OTHER cats and the possums in the neighborhood, and nail every other cat and the possums with either airsoft or paintballs.


ohh ic ic hmm thats really advanced... got anything else that remains within the confines of a win32 c++ console prog?
because i have yet to even begin anything graphical like opengl or opencl or even windows api and i know that i'm not even close to being finished with console app programming and i would like to stay within the confines of console apps untill i'm confident that i can do anything i want in it..

still i thankyou for the assignment and i'll make that my first project and show it off when i move onto graphical coding.
it won't take long i'm a quick learner. it's only taken me about 8 hours of learning spread over 2- 2 1/2 weeks to be able to make my 2 examples from scratch without looking at references

EDIT: actually i'm still going to try it if you can point me to some beginner tut's, i haven't found any resources or tutorials for programming with openCl as oh yet
 
Last edited:

Peter.Steele

FNG / Fresh Meat
Sep 6, 2006
2,128
779
0
Chambers of the Grand Council
ohh ic ic hmm thats really advanced... got anything else that remains within the confines of a win32 c++ console prog?
because i have yet to even begin anything graphical like opengl or opencl or even windows api and i know that i'm not even close to being finished with console app programming and i would like to stay within the confines of console apps untill i'm confident that i can do anything i want in it..

still i thankyou for the assignment and i'll make that my first project and show it off when i move onto graphical coding.
it won't take long i'm a quick learner. it's only taken me about 8 hours of learning spread over 2- 2 1/2 weeks to be able to make my 2 examples from scratch without looking at references

EDIT: actually i'm still going to try it if you can point me to some beginner tut's, i haven't found any resources or tutorials for programming with openCl as oh yet



I don't have any bookmarked on this computer, but ... mmmmmmm ... there was a bunch of stuff that I looked at on my desktop.


WAIT. No, not OpenCL, sorry. CV. OpenCV. Try looking for that instead!!!! Sorry!!!!! :eek:

I haven't done that much with it myself, but within the first hour or so of playing around I'd gotten a video feed from the camera and was able to work with it on a very basic level.

Shortly after that I got real busy with it and haven't been able to go back to it.
 

worluk

FNG / Fresh Meat
Nov 21, 2005
2,226
85
0
[...]

i can also do static and dynamic arrays and i've havn't even looked at how to make a windows API yet :/ so can you guys help me out by giveing me a program to make?

Hard to give you anything without knowing more what you have done so far.
Also what you are aiming for would be relevant. If you havent already done it, dive into pointers a little and do a single linked list to store and retrieve data. While it's not uber useful these days since there are more robust solutions out there it will give you an insight on pointers.

Since it looks like you havent already you should focus on the OO aspect of C++. Cant think of a decent "homework" for that atm though.

I don't have any bookmarked on this computer, but ... mmmmmmm ... there was a bunch of stuff that I looked at on my desktop.


WAIT. No, not OpenCL, sorry. CV. OpenCV. Try looking for that instead!!!! Sorry!!!!! :eek:

I haven't done that much with it myself, but within the first hour or so of playing around I'd gotten a video feed from the camera and was able to work with it on a very basic level.

Shortly after that I got real busy with it and haven't been able to go back to it.

No offense, but if really C++ is what he is after then using 3rd party libs is not the way to go. A decent understanding of C++'s core mechanisms would benefit him way more and typically also makes using those libs later on more easy. But i can understand that toying with graphics IO or doing GUIs with some API like Qt might be more interesting :)
 
Last edited:
  • Like
Reactions: radix

aktionman

FNG / Fresh Meat
May 10, 2006
399
25
0
Since it looks like you havent already you should focus on the OO aspect of C++. Cant think of a decent "homework" for that atm though.

+1

Perhaps start by rewriting those 2 programs using classes, inheritance, etc.?
 

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
OO aspect of C++? i'm sorry i don't know too much C++ lingo =(

and hmm i could rewrite my current works with classes and class inheritence that sounds good :) and oooo i totally forgot about pointers i'm gona have to relearn that.
 

worluk

FNG / Fresh Meat
Nov 21, 2005
2,226
85
0
OO = Object orientation.

What helped me getting deeper into C++ was writing a small MUD engine for a linux machine. :)
 
Last edited:
  • Like
Reactions: radix

Shadrach

Grizzled Veteran
May 2, 2006
2,688
400
83
Elitist Prick Ski Lodge
stian.freeshell.org
I remember hating pointers in C++. Never really got a hang of them either. Memory stuff is hard :( Then in later school years mostly did Java so didn't have to bother with them anymore :D I do believe however that it's good to start at the basics and C/++ would be the perfect language to learn the skills.

As well as being what is used for most of game development if that's where you want to go.

Here's a quick problem to solve for you, should be done in a couple minutes:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
 

Peter.Steele

FNG / Fresh Meat
Sep 6, 2006
2,128
779
0
Chambers of the Grand Council
Here's a quick problem to solve for you, should be done in a couple minutes:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".



... and we shall call it vuvuzela.exe.
 

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
i actually had a hard time with this one still so much to learn
but it's done :)
Code:
// Vuvuzela.exe
//by: falidell
#include <stdio.h>
#include <iostream>

int main()
{
using namespace std;
int x;
for(x=1;x<101;x++)
{
    if(x % 3 == 0 && x % 5 ==0){
     cout<< x <<"   FizzBuzz"<<endl;
     }
    else if(x % 3 == 0){
     cout << x <<"   Fizz"<<endl;
     }
    else if(x % 5 == 0){
     cout<< x <<"   Buzz"<<endl;
     }
     else{
     cout << x <<endl;
     }
}
system("pause");
}

linky linky to the .exe and the .cpp zip file:
http://www.filefront.com/17086047/vuvuzela.zip


Edit: btw does anyone know how to clear the console screen or pause the program without useing system?

i think it's in conio.h but my compiler doesn't like conio.h at all :(



Edit2: also binary tree???? and as far as classes go i can make simple classes but i can't seem to get classes to inhereit base classes for ex. online it said that if i wanted a class to "extend" something i would write it like:

Code:
class cRectangle : cPolygon
{
blah
};

however it gives me a ton of compilation errors when i do this wither i have cPolygon as a seperate file and included or if all my classes and extention classes inside one file along with the main funtion(and no i don't put the classes inside the main function)

and yes i know that classes only inhereit public and protected sections but not the private section of the parent class
 
Last edited:

Shadrach

Grizzled Veteran
May 2, 2006
2,688
400
83
Elitist Prick Ski Lodge
stian.freeshell.org

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
Nicely done, except you were supposed to print fizzbuzz instead* of the numbers, but that would be nitpicking :D

And you could do without the first if() if you do the endline at the end of the loop.

As to clearing the screen you can't do it in standard C++ so you'll need to code around it I think.
http://www.cprogramming.com/faq/cgi-bin/smartfaq.cgi?answer=1031963460&id=1043284385
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.20
nit picky *******.... lol :p JK thankyou =D and hmm i suppose it would be easier to put the endl at the end of the loop instead of for all the thingies...
 

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
i don't suppose anyone could tell me whats wrong with this??

Code:
#include <iostream>
class CPolygon {
      protected:
      int W,H;
      public:
             void Set(int a, int b)
             { W=a; H=b;)
};
class CSquare: public CPolygon {
      public:
             int Area ()
             ( return (W*H);)
             
};
class CTriangle: public CPolygon {
      public:
             int area ()
             {return (W*H/2);}
};


int main()
{
    using namespace std;
    CSquare Sqr1;
    Ctriangle Tri1;
    Sqr1.Set(4,5);
    Tri1.Set(4,5);
    cout <<" Square"<< endl;
    cout <<"Area:  " << Sqr1.Area()<<endl;
    cout <<" Triangle  "<<endl;
    cout <<"Area:  "<< Tri1.Area() <<endl;
    system("pause");
return 0;
}

when i try to compile it gives me a whole list of compilation errors yet i can find nothing wrong with it
 

worluk

FNG / Fresh Meat
Nov 21, 2005
2,226
85
0
Code:
#include <iostream>
class CPolygon {
      protected:
      int W,H;
      public:
             void Set(int a, int b)
             { W=a; H=b;[COLOR=Red])[/COLOR] // <= "}" instead
};
class CSquare: public CPolygon {
      public:
             int Area ()
             [COLOR=Red]([/COLOR] return (W*H);[COLOR=Red])[/COLOR] // <= { and }
             
};
class CTriangle: public CPolygon {
      public:
             int area ()
             {return (W*H/2);}
};


int main()
{
    using namespace std;
    CSquare Sqr1;
    Ctriangle Tri1;
    Sqr1.Set(4,5);
    Tri1.Set(4,5);
    cout <<" Square"<< endl;
    cout <<"Area:  " << Sqr1.Area()<<endl;
    cout <<" Triangle  "<<endl;
    cout <<"Area:  "<< Tri1.[COLOR=Red]A[/COLOR]rea() <<endl; [COLOR=White]//no Area function in Tri, only an "area"[/COLOR]
    system("pause");
return 0;
}
I assume you do that stuff on windows? In any case a decent makefile, proper indenting and split header and source files might be good practice.

For the errors see above, watch your parantheses. Those errors should nicely be reported by your compiler though.
Good idea might be to make a virtual or pure virtual function inside the Polygon for the area() function. Im quite sure its not intentional that you created differently named functions for CTriangle and CSquare.
 
Last edited:
  • Like
Reactions: radix

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
ooo geeze now i feel embarrassed :( lol thanks man =D i'm def going to check my Caps and "C++ Grammer" better!

also i've never heard of a virtual function =/ i'm going to have to look into that sounds useful

edit: lol and to be honest i never learned proper indenting and about the header and source file splitting.... i've never actually had a use for it yet and i've looked into it a number of times and all people tell me is "it contains definitions and the like" what the heck does does mean? when i did my own experimenting with it, Totally disregarded what they say "should" go in there, i put Functions, Namespaces and i even put a class into it and did the include in the Main.cpp
worked fine... i'm not sure if thats what it's for but it worked fine for me. so atm i only really use headers if i have more then two pages worth of function or namespace code that would normally make my main.cpp cluttered and hard to track
which so far i have yet to run into but i have a feeling that i will need it as i go more into OO programming .
 
Last edited:

worluk

FNG / Fresh Meat
Nov 21, 2005
2,226
85
0
You usually split up the class definitions and the implementation of the functions.

I tend to have a header and source file for each class ( probably a leftover of the times when i was forced to do Java)

In your example its more or less useless since your member functions are tiny.
You would put stuff like this into the header:
Code:
class CPolygon
{
   protected:
    int W,H;
   public:
     void Set(int a, int b);
     void Draw();
     void Rotate();
};

Then in the source file
Code:
#include "polygon.h" //lets assume the above class is in polygon.h

void CPolygon::Set(int a, int b)
{
   //your implementation here
}

void CPolygon::Draw()
{
   //your implementation here
}

void CPolygon::Rotate()
{
   //your implementation here
}


//end source :)

virtual functions are those that get overwritten or have to be overwritten by the child classes. In your example you could implement a "virtual int area()" function for the CPolygon class, then overwrite it with the respective implementations for the derived classes. You can then do a function like "void handleShape(CPolygon c)" which calls c.Area() somewhere in the code. With the virtual function it doesnt matter if its a CSquare or a CTriangle you hand over to the function, it will always call the correct Area function.