Hi,
i'm working on assignment i did part of it and i need help in some functions which are : add(Ta) and remove(int i)// an exception is thrown when adding a duplicate entry or when deleting with an out of bound index i .
the instructor gave us the main class and he asked us to provide the missing classes and functions the are needed to make a main program to run correctly .
i'd like to help me in those two functions .or to guide me how to work on them
note: th assign3.h & assign3.cpp thos classes that i worked on them
Assignment3.cpp that's from the instructor.
rama 0 Newbie Poster
#include "assign3.h"
template <class T>
Set <T>::Set(){};
template <class T>
Set <T>:: Set(T* t ,int c){};
template <class T>
Set <T>::Set(Set& s){};
template <class T>
Set <T> Set <T>::operator-(const Set <T> set){
return *this;
};
template <class T>
Set <T> Set <T>:: operator/(const Set <T> set){
return *this;
};
template <class T>
Set<T> Set<T>:: operator*(const Set<T> set){
return *this;
};
template <class T>
Set<T>& Set<T>:: operator=(const Set<T>& set){
return *this;
};
template <class T>
bool Set<T>:: operator==(const Set<T> set){
return false;
};
template <class T>
T Set<T>:: operator[](int index){
return *(this->s);
};
template <class T>
Set<T>::~Set(){
cout << "Set::~Set()" << endl;
}
template<class T>
void Set <T>::add(T a){};
template<class T>
void Set <T>::Delete(int i){};
template<class T>
void friendly_print(Set<T> X){};
template<class T1,class T2>
Pair<T1,T2>::Pair(T1 x, T2 y){};
template<class T1,class T2>
Pair<T1,T2> Pair<T1,T2>:: operator <<(Pair<T1,T2> p){};
template <class T1, class T2>
ostream& operator<<(ostream& os,const Pair<T1,T2>& p)
{
os << p.a<<" "<<p.b<<" "<<endl;
return os;
}
Set_Exception:: Set_Exception(string m){};
void Set_Exception::print(){
cout << "print the string message which contains a description of the exception"<<endl;
}
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
template<class T>class Set{
private:
T * s;
int size;
public:
Set();
Set(T*,int);
Set(Set<T>&);
Set<T> operator-(const Set<T>);
Set<T> operator/(const Set<T>);
Set<T> operator*(const Set<T>);
Set<T>& operator=(const Set<T>&);
bool operator ==(const Set<T>);
T operator[](int);
virtual ~Set();
void add(T a);
void Delete(int i);
friend void friendly_print(Set<T> X);
};
template<class T1,class T2>
class Pair{
private:
T1 a;
T2 b;
public:
Pair(T1 x, T2 y);
Pair operator <<(Pair<T1,T2>);
friend ostream& operator<<(ostream& os,const Pair<T1,T2>&p);
//template <class T1, class T2> friend ostream& operator<<(ostream& os, const Pair<T1,T2>& p) // To be implemented outside the class as shown below
//template <class T1, class T2> ostream& operator<<(ostream& os,const Pair<T1,T2>& p)
//{
// os << p.a<<" "<<p.b<<" "<<endl;
//return os;
};
class Set_Exception{
private:
string message;
public:
Set_Exception(string m);
void print();//{print the string message which contains a description of the exception}
};
#include "assign3.h"
void main() {
Set<int> A;
A.add(5); A.add(14); A.add(3); A.add(7); A.add(87); A.add(106);
try {
A.add(3);
}
catch (Set_Exception& e) {
e.print(); // must print to the screen (adding an existing element to the set)
}
A.Delete(1); // remove the first element in the set A
A.Delete (3); //remove the 3rd element in the set A
try {
A.Delete(-2);
}
catch (Set_Exception& e) {
e.print(); //must print to the screen (trying to delete using an out of bound index)
}
try {
A.Delete(20);
}
catch (Set_Exception& e) {
e.print(); //must print to the screen (trying to delete using an out of bound index)
}
int integer_list[10] = {3, 45, 67, 25, 64, 89, 36, 5, 106, 460};
Set <int> B(integer_list, 10);
Set<int> C1, C2, C3;
Set<Pair<int, int> > C4;
C1=A/B;
friendly_print (C1); // must print { 3, 5, 106}
C2= A+B;
friendly_print (C2); // must print { 5, 14, 3, 7, 87, 106, 45, 67, 25, 64, 89, 36, 5, 106, 460}
C3=A-B;
friendly_print (C3); // must print {14, 7, 87}
C4=C1*C3;
friendly_print (C4); // must print {(3,14),(3,7),(3,87),(5,14),(5,7),(5,87),(106,14),(106,7),(106, 87)}
char character_list[4]= {'a','f','t','j'};
Set <char> U(character_list, 4);
Set <char> V;
V.add('a');
V.add('n');
V.add('f');
Set<char> D1, D2, D3;
Set< Pair<char, char> > D4;
friendly_print (D1); //print {}
D1=U/V;
friendly_print(D1); // print {a, f}
D2=U+V;
friendly_print (D2); // print {a, f, t, j, n}
D3=U-V;
friendly_print (D3);// print {n}
D4=D1*D3;
friendly_print (D4); // print {(a,n), (f,n)}
if (U==U) cout << "U==V" << endl;
else cout << " U != V" << endl;
cout << "the second element in U is : "<< U[2] << endl;
try {
cout <<"the tenth element in U is : "<<U[10]<<endl;
}
catch (exception e) {
cout <<"out of bound access"<< endl;
}
Set<char> * set_ptr = new Set<char>();
set_ptr->add('d');
delete set_ptr; // must print (Set destructor is called)
}
rama 0 Newbie Poster
any one can help me?????
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.