Discrete mathematics practical-1, Assignments of Discrete Mathematics

Practical No-1 Discrete mathematics

Typology: Assignments

2019/2020

Available from 09/27/2021

adeeb-ahmed-1
adeeb-ahmed-1 🇮🇳

2

(3)

4 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Write a Program to create a SET A and determine the cardinality of SET for an input
array of elements (repetition allowed) and perform the following operations on the
SET.
CODE:
1) #include<iostream>
2) #include<cmath>
3)
4) using namespace std;
5)
6) class set {
7)
8) int *arr;int cnt;int pos;
9) int n;
10) public:
11) set()
12) {
13) n=0;
14) arr=0;
15) }
16)
17) void setsize();
18) void enterset();
19) void showset();
20) void uniqueset();
21) int cardinality();
22) bool member (int);
23) void powerset();
24) };
25)
26) void set::setsize()
27) {
28)
29) cout<<"\n\nenter the size or array :) : ";
30) cin>>n;
31) arr=new int [n];
32)
33)
34) }
35)
36) void set ::enterset()
37) {
38)
39) cout<<"\nenter elements of set:) : ";
40) for(int i=0;i<n;i++)
41) {
42) cin>>arr[i];
43)
44) }
45)
46) }
47)
pf3
pf4

Partial preview of the text

Download Discrete mathematics practical-1 and more Assignments Discrete Mathematics in PDF only on Docsity!

1. Write a Program to create a SET A and determine the cardinality of SET for an input

array of elements (repetition allowed) and perform the following operations on the

SET.

CODE:

  1. #include

  2. #include

  3. using namespace std;

  4. class set {

  5. int *arr;int cnt;int pos;

  6. int n;

  7. public:

  8. set()

  9. {

  10. n=0;

  11. arr=0;

  12. }

  13. void setsize();

  14. void enterset();

  15. void showset();

  16. void uniqueset();

  17. int cardinality();

  18. bool member (int);

  19. void powerset();

  20. };

  21. void set::setsize()

  22. {

  23. cout<<"\n\nenter the size or array :) : ";

  24. cin>>n;

  25. arr=new int [n];

  26. }

  27. void set ::enterset()

  28. {

  29. cout<<"\nenter elements of set:) : ";

  30. for(int i=0;i<n;i++)

  31. {

  32. cin>>arr[i];

  33. }

  34. }

  35. void set::showset()

  36. {

  37. cout<<"\nentered set : ";

  38. for(int i=0;i<n-1;i++)

  39. {

  40. cout<<arr[i]<<" ,";

  41. }

  42. cout<<arr[n-1];

  43. }

  44. void set::uniqueset()

  45. {

  46. int i,j;

  47. int count = 1;

  48. for(i = 0; i < n; i++)

  49. {

  50. for(j = 0; j < n; j++)

  51. {

  52. if(arr[i] == arr[j] && i != j)

  53. break;

  54. }

  55. if(j == n )

  56. {

  57. cout<<"\nNon repeating element :"<<arr[i];

  58. ++count;

  59. }

  60. }

  61. }

  62. int:: set::cardinality()

  63. {

  64. return n;

  65. }

  66. bool set::member(int num)

  67. {

  68. for(int i=0; i<n; i++)

  69. {

  70. if(arr[i]==num)

  71. {

  72. cnt=1;

  73. pos=i+1;

  74. break;

  75. }

  76. }

  77. if(cnt==0)

  78. {

  79. cout<<"\n Element Not Found..!!";

  80. }

  81. else

  82. {

  83. cout<<"\n Element "<<num<<" Found At Position "<<pos;

  84. }

OUTPUT: