dru4 Posted May 29, 2013 Report Share Posted May 29, 2013 Описать класс «множество», позволяющий выполнять основные операции – добавление и удаление элемента, пересечение, объединение и удаление множеств Link to comment Share on other sites More sharing options...
dru4 Posted May 29, 2013 Author Report Share Posted May 29, 2013 пожалуйста ребят Link to comment Share on other sites More sharing options...
SholpanB Posted May 31, 2013 Report Share Posted May 31, 2013 помогите!!!! очень надо!! дана действительная матрица размера nxm. получить последовательность b1,…,bn, где bk – это число отрицательных элементов в k-й строке. Link to comment Share on other sites More sharing options...
Тролль Posted May 31, 2013 Report Share Posted May 31, 2013 (edited) SholpanB #include<iostream>using namespace std;int main(){int i,j,n,m,b[20]; float a[20][20];cout<<"Enter the dimensions of the matrix: "; cin>>n>>m;for(i=0;i< n;i++){ cout<<"Enter "<< m<<" elements of line "<<i+1<<": "; for(j=0;j< m;j++)cin>>a[i][j];}for(i=0;i<n;i++){b[i]=0; for(j=0;j<m;j++)if(a[i][j]<0)++b[i];}cout<<endl<<"Number of negativ elements in the lines: "<<endl;for(i=0;i<n;i++)cout<<i+1<<':'<<b[ i]<<endl; cin.get(); cin.get();} Edited May 31, 2013 by Тролль Link to comment Share on other sites More sharing options...
Тролль Posted May 31, 2013 Report Share Posted May 31, 2013 (edited) Описать класс «множество», позволяющий выполнять основные операции – добавление и удаление элемента, пересечение, объединение и удаление множеств #include <iostream>#define te template <typename T>using namespace std;const int MaxSize=100;te class Set { int len; T m[MaxSize]; int find(T ch);public: Set(){len=0;} int getLength(){return len;} void showset(); bool isMember(T ch); Set operator +(T ch); Set operator -(T ch); Set operator +(Set ob2); Set operator -(Set ob2); Set operator +=(T b); Set operator -=(T b); Set operator *(Set ob2);}; te int Set<T>::find(T ch){int i; for(i=0;i<len;i++)if(m[i]==ch)return i; return -1;} te void Set<T>::showset(){cout<<"{ "; for(int i=0;i<len;i++)cout<<m[i]<<" "; cout<<"}\n";}te bool Set<T>::isMember(T ch){return find(ch)!=-1;} te Set<T> Set<T>::operator +(T ch){ Set newset; if(len==MaxSize){cout<<"Set is full.\n"; return *this;} newset=*this; if(find(ch)==-1){newset.m[newset.len]=ch; newset.len++;} return newset;} te Set<T> Set<T>::operator +=(T b){*this=*this+b; return *this;} te Set<T> Set<T>::operator -(T c){ Set newset; int i=find©; for(int j=0;j<len;j++)if(j!=i)newset=newset+m[j]; return newset;} te Set<T> Set<T>::operator -=(T b){*this=*this-b; return *this;}te Set<T> Set<T>::operator +(Set ob2){ Set<T> newset=*this; for(int i=0;i<ob2.len;i++)newset=newset+ob2.m[i]; return newset;} te Set<T> Set<T>::operator -(Set ob2){ Set newset=*this; for(int i=0;i<ob2.len;i++)newset=newset-ob2.m[i]; return newset;} te Set<T> Set<T>::operator *(Set ob2){ Set newset; for(int i=0;i<ob2.len;i++)if(find(ob2.m[i])>=0)newset=newset+ob2.m[i]; return newset;} int main(){ cout<<"TEST"<<'\n'; Set<char> s1,s2,s3; s1=s1+'A'; s1=s1+'B'; cout<<"s1+'A'+'B': "; s1.showset(); s1+='C'; cout<<"s1+='C': "; s1.showset(); s1-='B'; cout<<"s1-='B': "; s1.showset(); cout<<"Members 'A' 'B' 'C': "<<boolalpha<< s1.isMember('A')<<", "<<s1.isMember('B')<<", "<<s1.isMember('C')<<'\n'; s1=s1-'A'; cout<<"s1-'A': "; s1.showset(); s1=s1+'A'+'B'+'C'; cout<<"s1=s1+'A'+'B'+'C': "; s1.showset(); s2=s2+'A'+'D'+'E'; cout<<"s2=s2+'A'+'D'+'E': "; s2.showset(); s3=s1*s2; cout<<"s3=s1*s2: "; s3.showset(); s3=s1+s2; cout<<"s3=s1+s2: "; s3.showset(); s3=s3-s1; cout<<"s3=s3-s1: "; s3.showset(); cin.get();} Edited May 31, 2013 by Тролль Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now