Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. using namespace std;
  5. vector<int>codomain;
  6. vector<int>domain;
  7. vector<int>range;
  8. bool checkOnto(){
  9.     if (range.size() != codomain.size())
  10.         return false;
  11.     for (int i = 0; i < domain.size(); i++){
  12.         bool isIncluded = false;
  13.         for (int j = 0; j < range.size(); j++){
  14.             if (codomain[i] == range[j])
  15.                 isIncluded = true;
  16.         }
  17.         if (isIncluded == false){
  18.             return false;
  19.         }
  20.     }
  21.     return true;
  22. }
  23. int main(){
  24.     int n=0;
  25. int con,t,x,y;
  26.     cout << "Enter the number of elements in the codomain: ";
  27.     cin >> n;
  28.     cout << "Enter the number of connections: ";
  29.     cin >> con;
  30.     cout << "Enter the codomain: " << endl;
  31.     for (int i = 0; i < n; i++){
  32.         cin >> t;
  33.         codomain.push_back(t);
  34.     }
  35.     cout << "Enter the connections (Ex. 2 3) and press enter: " << endl;
  36.     for (int i = 0; i < con; i++){
  37.         cout << "C" << i + 1 << ": ";
  38.         cin >> x >> y;
  39.         domain.push_back(x);
  40.         range.push_back(y);
  41.     }
  42.     if (checkOnto())
  43.         cout << "The function is onto" ;
  44.     else
  45.         cout << "The function is not onto";
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement