Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file prog1 output.txt. Write a title before the output of each operation.
1. Union
2. Intersection
3. A - B
4. Decide if (A ⊂ B).
Program 2 – 50 points
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file prog2 output.txt and the standard output. Write a title before the output of each operation.
1. (A∪B)∪C.
2. A∪(B∩C).
3. (A∪B)∩(A∪C). HINTS
You may want to use arrays.
Pay special attention to the parentheses because they indicate the order. For example: (A ∪ B) ∪ C means to compute (A ∪ B) first, and then ∪C.
Consider reusing the algorithms for union and intersection that
you have defined already. For example, to compute (A ∪ B) ∪
C:
First, compute A ∪ B using the function that computes the union
that you already defined. Let’s say that you store that result in
an array R.
Then, compute R ∪ C using the function that computes the union that you already defined.
Program-1:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
char set[2][1000];
int index[2] = { 0, 0 };
ifstream inputFile1("prog1input.txt");
int sset = 0;
while (getline(inputFile1, line)) {
for (int i = 0; i <
line.length(); i++) {
if (line[i] != '
') {
set[sset][index[sset]++] = line[i];
}
}
sset++;
}
inputFile1.close();
ofstream outputFile1;
outputFile1.open("prog1output.txt", ios::trunc);
//Union
outputFile1 << "1. Union\n";
{
bool vis[256] = { 0 };
for (int i = 0; i < index[0];
i++) {
if
(!vis[set[0][i]]) {
vis[set[0][i]] = !vis[set[0][i]];
outputFile1 << set[0][i] << "
";
}
}
for (int i = 0; i < index[1];
i++) {
if
(!vis[set[1][i]]) {
vis[set[1][i]] = !vis[set[1][i]];
outputFile1 << set[1][i] << "
";
}
}
}
outputFile1 << "\n";
outputFile1 << "2. Intersection\n";
//Intersection
{
bool vis[256] = { 0 };
for (int i = 0; i < index[0];
i++) {
vis[set[0][i]] =
1;
}
for (int i = 0; i < index[1];
i++) {
if
(vis[set[1][i]]) {
outputFile1 << set[1][i] << "
";
}
}
}
outputFile1 << "\n";
outputFile1 << "3. A-B\n";
//A-B
{
bool vis[256] = { 0 };
for (int i = 0; i < index[1];
i++) {
vis[set[1][i]] =
1;
}
for (int i = 0; i < index[0];
i++) {
if
(!vis[set[0][i]]) {
outputFile1 << set[0][i] << "
";
}
}
}
outputFile1 << "\n";
outputFile1 << "4. Decide if (A is subset of
B)\n";
//A is subset of B
{
bool vis[256] = { 0 };
for (int i = 0; i < index[0];
i++) {
vis[set[0][i]] =
1;
}
int cnt = 0;
for (int i = 0; i < index[1];
i++) {
if
(vis[set[1][i]]) {
cnt++;
}
}
if (cnt == index[0]) {
outputFile1
<< "Yes, A is a subset B";
}
else {
outputFile1
<< "No, A is not a subset of B";
}
}
outputFile1.close();
return 0;
}



Input:

Output:

Program 2:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
char set[3][1000];
int index[3] = { 0, 0, 0 };
ifstream inputFile1("prog2input.txt");
int sset = 0;
while (getline(inputFile1, line)) {
for (int i = 0; i <
line.length(); i++) {
if (line[i] != '
') {
set[sset][index[sset]++] = line[i];
}
}
sset++;
}
inputFile1.close();
ofstream outputFile1;
outputFile1.open("prog2output.txt", ios::trunc);
//Union (A u B) u C
outputFile1 << "1. (A u B) u C\n";
{
bool vis[256] = { 0 };
for (int i = 0; i < index[0];
i++) {
if
(!vis[set[0][i]]) {
vis[set[0][i]] = !vis[set[0][i]];
outputFile1 << set[0][i] << "
";
}
}
for (int i = 0; i < index[1];
i++) {
if
(!vis[set[1][i]]) {
vis[set[1][i]] = !vis[set[1][i]];
outputFile1 << set[1][i] << "
";
}
}
for (int i = 0; i < index[2];
i++) {
if
(!vis[set[2][i]]) {
vis[set[2][i]] = !vis[set[2][i]];
outputFile1 << set[2][i] << "
";
}
}
}
outputFile1 << "\n";
outputFile1 << "2. A u (B n C)\n";
//A u (B n C)
{
bool vis[256] = { 0 };
bool vis1[256] = { 0 };
for (int i = 0; i < index[1];
i++) {
vis[set[1][i]] =
1;
}
for (int i = 0; i < index[2];
i++) {
if
(vis[set[2][i]]) {
outputFile1 << set[2][i] << "
";
vis1[set[2][i]] = 1;
}
}
for (int i = 0; i < index[0];
i++) {
if
(!vis1[set[0][i]]) {
outputFile1 << set[0][i] << "
";
}
}
}
outputFile1 << "\n";
outputFile1 << "3. (A u B) n (A u C)\n";
//(A u B) n (A u C)
{
bool vis1[256] = { 0 };
char aub[2000];
int iaub = 0;
for (int i = 0; i < index[0];
i++) {
if
(!vis1[set[0][i]]) {
vis1[set[0][i]] = !vis1[set[0][i]];
//outputFile1 << set[0][i] << "
";
aub[iaub++] = set[0][i];
}
}
for (int i = 0; i < index[1];
i++) {
if
(!vis1[set[1][i]]) {
vis1[set[1][i]] = !vis1[set[1][i]];
//outputFile1 << set[1][i] << "
";
aub[iaub++] = set[1][i];
}
}
bool vis2[256] = { 0 };
char buc[2000];
int ibuc = 0;
for (int i = 0; i < index[1];
i++) {
if
(!vis2[set[1][i]]) {
vis2[set[1][i]] = !vis2[set[1][i]];
//outputFile1 << set[0][i] << "
";
buc[ibuc++] = set[1][i];
}
}
for (int i = 0; i < index[2];
i++) {
if
(!vis2[set[2][i]]) {
vis2[set[2][i]] = !vis2[set[2][i]];
//outputFile1 << set[1][i] << "
";
buc[ibuc++] = set[2][i];
}
}
bool vis[256] = { 0 };
for (int i = 0; i < iaub; i++)
{
vis[aub[i]] =
1;
}
for (int i = 0; i < ibuc; i++)
{
if (vis[buc[i]])
{
outputFile1 << buc[i] << " ";
}
}
}
outputFile1.close();
return 0;
}




Input:

Output:

Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Q4) Write a C program named "hw3q4.c” that takes three string inputs from the command line arguments that represent file names. The first and second files contain four sorted integer numbers that represent set elements. The main process creates a child process that shares the three files. The child process determines the intersection set of two sets and saves the line: "Child process PID: xxxx Intersection of (x, x, x, x) and (y, y, y, y) (z, z, z, z)"...
Program has to be in C# language
Write a computer program that takes two sets (let the user determine the cardinality of each set and enter them manually) and calculates the following operations: Union Intersection Difference (set1 - set2) Cartesian product (set2 X set1) Check whether set2 is a subset of set1 or set1 is a subset of set2 Find the powerset of set1 and print out its elements and cardinality
u are to write a program in Java that takes two sets of up to 5 symbols(letters, numbers or any characters) and prints the cartesian product of the two sets. The program should allow the user to enter the characters for each set and the output should, consist of the name of each set followed by the characters and on the following line print the cartesian product. Example: {1,3,*} X {3,?,D} = {(1,3),(1,?),(1,D),(3,3),(3,?),(3,D,(*,3),(*,?),(*,D)} or {2,3,5,7} X (5,6} = {(2,5),(2,6),(3,5),(3,6),(5,5),(5,6),(7,5),(7,6)}
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
write a program in c ++ that reads the length and width of a rectangle from a file named input.txt and write the area and perimeter of the rectactangle to file named output.txt
1. use c++ write a c++ program that reads 10 integers from a file named input.txt in this file the 10 integers wil be on a single line with space between the. calculate the average of these numbers and then write his number to a file named output.txt. if the program is unable to successfully complete the file operations then display eero message to the console.
C++ Write a program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Also you may wish to use the strlen( ) function. Output: After the program generates output.txt, the code should display the contents of the file on the screen...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...
C++ Programming question
Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...
C++
Write a program based on 8_lb that reads in the integer data from "input.txt" into a vector. Please prompt for the file name and append the "txt". Then create another vector where each element is the original vector times 10. Create a variable total and sum up the numbers from the second vector. The total should be 17510. Then write the data from the original vector and the 10 times vector to a file. See output.txt for the format....