Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,173 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,946 people online right now. Registration is fast and FREE... Join Now!




C++ PLEASE HELP

 
Reply to this topicStart new topic

C++ PLEASE HELP, C++ Homework Questions

georgie024
5 Dec, 2007 - 06:46 AM
Post #1

New D.I.C Head
*

Joined: 5 Dec, 2007
Posts: 2


My Contributions
Can sombody please help me with those 4 questions PLEASE i need it for my assignment
THANK YOU

1. You are to write the truncate method and place it in a file called 11.cpp. The truncate method must search through the link list and terminate the list once the item passed as an argument is found or passed in the list. See the example output above. Assume that each link in the list is allocated dynamically in the addnode method and that the addnode method places the item in the list in sorted order. If the method performs a truncation (at least on item is removed from the list) your method must return true. If no item are removed your method must return false.

CODE
#include <string>
#include <iostream>

using namespace std;
class link {
    string word;
    link *next;

public:
    link (string n) {word = n; next = NULL;}
    void setNext (link *n) {next = n;}
    link *getNext() const {return next;}
    string getWord() const {return word;}
};

class link list
{
private:
    link *first;
publik:
    linklist() {
        first=NULL;
    }
//Provide _puts item in list in sorted order
    void add item(string n);
//You MUST WRITE TRUNCATE
    bool truncate (string n);
//Provide
    friend ostream &operator <<(ostream &out, const linklist &1);
};

main () {
    t.additem ("Z");
    t.additem ("U");
    t.additem ("R");
    t.additem ("A");
    t.additem ("B");
    count <<Before truncate = <<endl<< t;
    t.truncate ("p");
    count <<After truncation = <<endl<<t;



Before truncation
A
B
R
U
Z
After
A
B



2.
CODE

#include <iostream>

using namspace std;

class base {
    static int count;
    int id;
public:
    base (int id){
        this _>id = id
            count ++
            count <<"Base Creating ["<count<c"] "<<this-> id << endl;
    }
    base (const base &rhs) {
        this ->id = rhs.id;
        count ++
            count <<"Base Copied ["<count<c"] "<<this-> id << endl;
    }
    ~base(){
        count <<"Base Delatin ["<count<c"] "<<this-> id << endl;
        count --;
    }
    static int getCount() {return count;}
};
int base :: count =0;
class der: public base {
    int dval;
publik:
    der (int dval): base (dval) {
        this -> dval = dval;
        count <<"Dervited Constain:" <<dval << endl;
    }
    ~ der(){
        count <<"Dervided Deleted" <<endl;
    }
};
int main ()
{
    count <<"STR of Pro." <<base :: getCount() <<endl;
    base *b1 = new base (300);
    base b2 (200);
    der *d1 = new der (100);
    der d2 (*d1);
    delete d1;
    count <<"END of proc "<<Base :: getCount() <<endl;
}



OUTPUT:

3. Complete the Code small Int Class
Class will store only positive values 0 and 1000.
If an attempt to set the small int to a value less then 0 is made the value variable in the class must be set to 0. If attempt Small 1000 must set to 1000. The value must never go outside the range of 0 to 1000.

CODE
class SmallInt {
    int value;
public:
    SmallInt (int v); //Constructor
    void setValue (int v); //Set value
    int getValue () const; //Get value
    //Add two SmallInt together
    SmallInt operator + (const SmallInt &rhs);
    //Add into SmallInt
    SmallInt operator + (int x);
    //Add operator for a SmallInt an int returns it
    friend int operator + (int x, const SmallInt &rhs);
}
;

main (){
    SmallInt s1 (1001, s 2(200);
    count << s1.getValue() <<endl;
    s1=s1+s2
        cout <<s1 getValue() <<end;
    s1=s1+800;
    cout << s1.getValue() <<endl;
    int x=44+SmallInt (-44);
    count <<x<<endl;
    cin.get()
}



100
300
100 0
44


4.
A= 2*w*d+2*h*d+2*w*h

Cube
Calculate surface area

CODE
using namespace std;
class TreeDshape
{
    string name;
public:
    TreeDshape(string inname){
        name= inname;
    }
    string getName() const {return name;}
    virtual double surfacearea() const=0;
    frend ostream operator << (ostream & out, ThreeDshape & Td);
};
ostream& operator << (Ostream& out, ThreeDshape & Td);
{
    out <<Td.getName()<<"has a surfave area of"
        <<Td.surfacearea();
    return out;
}




Code for Class
Phonemically create a Cube
h=6.5
w=4.4
d=1.4

Point out cube Object
Destroy the cube object before the program terminate.

*Mod Edit: Added code tags: code.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ PLEASE HELP
5 Dec, 2007 - 07:52 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Please note that DIC is not here to do your homework for you. We can assist with questions and helping you get code working, or explaining hard to understand concepts. But, posting your homework assignment is just not a way to encourage people to help you.


User is offlineProfile CardPM
+Quote Post

georgie024
RE: C++ PLEASE HELP
6 Dec, 2007 - 11:26 AM
Post #3

New D.I.C Head
*

Joined: 5 Dec, 2007
Posts: 2


My Contributions
Can sombady please help me with those 4 questions, it is very important because it will help me understand my assignment better.
PLEASE

1. You are to write the truncate method and place it in a file called 11.cpp. The truncate method must search through the link list and terminate the list once the item passed as an argument is found or passed in the list. See the example output above. Assume that each link in the list is allocated dynamically in the addnode method and that the addnode method places the item in the list in sorted order. If the method performs a truncation (at least on item is removed from the list) your method must return true. If no item are removed your method must return false.

CODE

#include <string>
#include <iostream>

using namespace std;
class link {
    string word;
    link *next;

public:
    link (string n) {word = n; next = NULL;}
    void setNext (link *n) {next = n;}
    link *getNext() const {return next;}
    string getWord() const {return word;}
};

class link list
{
private:
    link *first;
publik:
    linklist() {
        first=NULL;
    }
//Provide _puts item in list in sorted order
    void add item(string n);
//You MUST WRITE TRUNCATE
    bool truncate (string n);
//Provide
    friend ostream &operator <<(ostream &out, const linklist &1);
};

main () {
    t.additem ("Z");
    t.additem ("U");
    t.additem ("R");
    t.additem ("A");
    t.additem ("B");
    count <<Before truncate = <<endl<< t;
    t.truncate ("p");
    count <<After truncation = <<endl<<t;



Before truncation
A
B
R
U
Z
After
A
B



2.

CODE

#include <iostream>

using namspace std;

class base {
    static int count;
    int id;
public:
    base (int id){
        this _>id = id
            count ++
            count <<"Base Creating ["<count<c"] "<<this-> id << endl;
    }
    base (const base &rhs) {
        this ->id = rhs.id;
        count ++
            count <<"Base Copied ["<count<c"] "<<this-> id << endl;
    }
    ~base(){
        count <<"Base Delatin ["<count<c"] "<<this-> id << endl;
        count --;
    }
    static int getCount() {return count;}
};
int base :: count =0;
class der: public base {
    int dval;
publik:
    der (int dval): base (dval) {
        this -> dval = dval;
        count <<"Dervited Constain:" <<dval << endl;
    }
    ~ der(){
        count <<"Dervided Deleted" <<endl;
    }
};
int main ()
{
    count <<"STR of Pro." <<base :: getCount() <<endl;
    base *b1 = new base (300);
    base b2 (200);
    der *d1 = new der (100);
    der d2 (*d1);
    delete d1;
    count <<"END of proc "<<Base :: getCount() <<endl;
}


OUTPUT:




3. Complete the Code small Int Class
Class will store only positive values 0 and 1000.
If an attempt to set the small int to a value less then 0 is made the value variable in the class must be set to 0. If attempt Small 1000 must set to 1000. The value must never go outside the range of 0 to 1000.

CODE

class SmallInt {
    int value;
public:
    SmallInt (int v); //Constructor
    void setValue (int v); //Set value
    int getValue () const; //Get value
    //Add two SmallInt together
    SmallInt operator + (const SmallInt &rhs);
    //Add into SmallInt
    SmallInt operator + (int x);
    //Add operator for a SmallInt an int returns it
    friend int operator + (int x, const SmallInt &rhs);
}
;

main (){
    SmallInt s1 (1001, s 2(200);
    count << s1.getValue() <<endl;
    s1=s1+s2
        cout <<s1 getValue() <<end;
    s1=s1+800;
    cout << s1.getValue() <<endl;
    int x=44+SmallInt (-44);
    count <<x<<endl;
    cin.get()
}


100
300
100 0
44



4.
A= 2*w*d+2*h*d+2*w*h

Cube
Calculate surface area

CODE

using namespace std;
class TreeDshape
{
    string name;
public:
    TreeDshape(string inname){
        name= inname;
    }
    string getName() const {return name;}
    virtual double surfacearea() const=0;
    frend ostream operator << (ostream & out, ThreeDshape & Td);
};
ostream& operator << (Ostream& out, ThreeDshape & Td);
{
    out <<Td.getName()<<"has a surfave area of"
        <<Td.surfacearea();
    return out;
}



Code for Class
Phonemically create a Cube
h=6.5
w=4.4
d=1.4

Point out cube Object
Destroy the cube object before the program terminate.


* Edit: This post is somewhat of a mess. In the future use code tags, please and thanks. code.gif

This post has been edited by Martyr2: 6 Dec, 2007 - 11:39 AM
User is offlineProfile CardPM
+Quote Post

Bench
RE: C++ PLEASE HELP
6 Dec, 2007 - 11:47 AM
Post #4

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 617



Thanked: 14 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
Do you have any specific questions? pasting your assignment along with a half-baked attempt to write some code, which hasn't even been tested through a compiler, isn't going to get you very far.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ PLEASE HELP
6 Dec, 2007 - 11:57 AM
Post #5

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Topics merged. Please do not duplicate topics.

This is a warning! Your post does not comply with the forum rules. If you would like to continue to use DIC please read the forum rules

Give descriptive titles, ask specific questions.

If you do not understand the teachers question, post your thoughts -- your best effort at answering the question and you will find people more than willing to help.

Do not just post your homework and expect us to do it for you!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month