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:

New Topic/Question
Reply



MultiQuote



|