ADVERTISEMENT
ADVERTISEMENT

Ruby program to check a set is a superset of another set

Ruby Example: Write a program to check a set is a superset of another set.
Submitted by Nidhi, on February 07, 2022

Problem Solution:

In this program, we will create two objects of the Set class and add items into created sets. Then we will check a set is a superset of another set using the ">=" operator.

Program/Source Code:

The source code to check a set is a superset of another set is given below. The given program is compiled and executed successfully.

# Ruby program to check a set is a 
# superset of another set

require 'set';

setObj1 = Set.new();
setObj2 = Set.new();

setObj1.add(101);
setObj1.add(102);
setObj1.add(103);
setObj1.add(104);
setObj1.add(105);

setObj2.add(103);
setObj2.add(104);
setObj2.add(105);

if setObj1 >= setObj2
    puts "setObj1 is the superset of setObj2";
else
    puts "setObj1 is not the superset of setObj2";
end

Output:

setObj1 is the superset of setObj2

Explanation:

In the above program, we imported the "set" package using the "require" statement. Then we created two objects setObj1, setObj2 of the Set class using the new() method and added items into created set using add() method of the Set class. After that, we checked set setObj1 is the superset of setObj2 using the ">=" operator and printed the appropriate message.

Ruby Set Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.