Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- using namespace std;
- vector<int>codomain;
- vector<int>domain;
- vector<int>range;
- bool checkOnto(){
- if (range.size() != codomain.size())
- return false;
- for (int i = 0; i < domain.size(); i++){
- bool isIncluded = false;
- for (int j = 0; j < range.size(); j++){
- if (codomain[i] == range[j])
- isIncluded = true;
- }
- if (isIncluded == false){
- return false;
- }
- }
- return true;
- }
- int main(){
- int n=0;
- int con,t,x,y;
- cout << "Enter the number of elements in the codomain: ";
- cin >> n;
- cout << "Enter the number of connections: ";
- cin >> con;
- cout << "Enter the codomain: " << endl;
- for (int i = 0; i < n; i++){
- cin >> t;
- codomain.push_back(t);
- }
- cout << "Enter the connections (Ex. 2 3) and press enter: " << endl;
- for (int i = 0; i < con; i++){
- cout << "C" << i + 1 << ": ";
- cin >> x >> y;
- domain.push_back(x);
- range.push_back(y);
- }
- if (checkOnto())
- cout << "The function is onto" ;
- else
- cout << "The function is not onto";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement