C++ PLEASE HELP

C++ Homework Questions

Page 1 of 1

4 Replies - 2117 Views - Last Post: 06 December 2007 - 12:57 PM Rate Topic: -----

#1 georgie024   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-December 07

C++ PLEASE HELP

Post icon  Posted 05 December 2007 - 07:46 AM

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.

#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.
#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.

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

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:

Is This A Good Question/Topic? 0
  • +

Replies To: C++ PLEASE HELP

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ PLEASE HELP

Posted 05 December 2007 - 08:52 AM

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.
Was This Post Helpful? 0
  • +
  • -

#3 georgie024   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-December 07

Re: C++ PLEASE HELP

Posted 06 December 2007 - 12:26 PM

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.

#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.

#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.

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

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:

This post has been edited by Martyr2: 06 December 2007 - 12:39 PM

Was This Post Helpful? 0
  • +
  • -

#4 Bench   User is offline

  • D.I.C Lover
  • member icon

Reputation: 945
  • View blog
  • Posts: 2,464
  • Joined: 20-August 07

Re: C++ PLEASE HELP

Posted 06 December 2007 - 12:47 PM

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.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ PLEASE HELP

Posted 06 December 2007 - 12:57 PM

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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1