anishcana / jovial

SpringAjaxModule
0 stars 0 forks source link

Sets and groups #7

Open anishcana opened 6 months ago

anishcana commented 6 months ago

include

include

include

include

// Function to find which group the string belongs to std::string findGroup(const std::string& str, const std::map<std::string, std::set>& groupsMap) { for (const auto& group : groupsMap) { if (group.second.find(str) != group.second.end()) { return group.first; } } return "None"; // If string doesn't belong to any group }

int main() { // Define sets of strings representing different groups std::set group1 = {"apple", "banana", "orange"}; std::set group2 = {"car", "bus", "train"}; std::set group3 = {"dog", "cat", "rabbit"};

// Create a map to store group names and their corresponding sets of strings
std::map<std::string, std::set<std::string>> groupsMap;

// Insert groups into the map with their corresponding keys
groupsMap["group1"] = group1;
groupsMap["group2"] = group2;
groupsMap["group3"] = group3;

// Test the findGroup function
std::string testString = "banana";
std::string group = findGroup(testString, groupsMap);
if (group != "None") {
    std::cout << "The string belongs to group: " << group << std::endl;
} else {
    std::cout << "The string does not belong to any group." << std::endl;
}

return 0;

}

anishcana commented 6 months ago

include

include

include

include

// Function to add a group to the groups map void addGroup(const std::set& group, const std::string& groupName, std::map<std::set, std::string>& groupsMap) { groupsMap[group] = groupName; }

// Function to find which group(s) the string belongs to std::set findGroup(const std::string& str, const std::map<std::set, std::string>& groupsMap) { std::set result; for (const auto& group : groupsMap) { if (group.first.find(str) != group.first.end()) { result.insert(group.second); } } return result; }

// Function to print the result void printResult(const std::string& str, const std::set& groups) { if (!groups.empty()) { std::cout << "The string '" << str << "' belongs to group(s): "; for (const auto& group : groups) { std::cout << group << " "; } std::cout << std::endl; } else { std::cout << "The string '" << str << "' does not belong to any group." << std::endl; } }

int main() { // Define sets of strings representing different groups std::set group1 = {"apple", "banana", "orange"}; std::set group2 = {"car", "bus", "train"};

// Create a map to store sets of group names and their corresponding sets of strings
std::map<std::set<std::string>, std::string> groupsMap;

// Add groups to the map
addGroup(group1, "group1", groupsMap);
addGroup(group2, "group2", groupsMap);

// Test the findGroup function
std::string testString = "banana";
std::set<std::string> groups = findGroup(testString, groupsMap);

// Print the result
printResult(testString, groups);

return 0;

}

anishcana commented 6 months ago

include

include

include

include

include "groups.h"

// Function to add a group to the groups map void addGroup(const std::set& group, const std::string& groupName, std::map<std::set, std::string>& groupsMap) { groupsMap[group] = groupName; }

// Function to find which group(s) the string belongs to std::set findGroup(const std::string& str, const std::map<std::set, std::string>& groupsMap) { std::set result; for (const auto& group : groupsMap) { if (group.first.find(str) != group.first.end()) { result.insert(group.second); } } return result; }

// Function to print the result void printResult(const std::string& str, const std::set& groups) { if (!groups.empty()) { std::cout << "The string '" << str << "' belongs to group(s): "; for (const auto& group : groups) { std::cout << group << " "; } std::cout << std::endl; } else { std::cout << "The string '" << str << "' does not belong to any group." << std::endl; } }

int main() { // Create a map to store sets of group names and their corresponding sets of strings std::map<std::set, std::string> groupsMap;

// Add groups to the map
addGroup(group1, "group1", groupsMap);
addGroup(group2, "group2", groupsMap);

// Test the findGroup function
std::string testString = "banana";
std::set<std::string> groups = findGroup(testString, groupsMap);

// Print the result
printResult(testString, groups);

return 0;

}

anishcana commented 6 months ago

ifndef GROUPS_H

define GROUPS_H

include

include

extern const std::set group1; extern const std::set group2;

endif // GROUPS_H

anishcana commented 6 months ago

ifndef GROUPS_H

define GROUPS_H

include

include

const std::set group1 = {"apple", "banana", "orange"}; const std::set group2 = {"car", "bus", "train"};

endif // GROUPS_H

anishcana commented 6 months ago

include

include

include

include

include "groups.h"

// Function to add a group to the groups map void addGroup(const std::set& group, const std::string& groupName, std::map<std::set, std::string>& groupsMap) { groupsMap[group] = groupName; }

// Function to find which group(s) the string belongs to std::set findGroup(const std::string& str, const std::map<std::set, std::string>& groupsMap) { std::set result; for (const auto& group : groupsMap) { if (group.first.find(str) != group.first.end()) { result.insert(group.second); } } return result; }

// Function to print the result void printResult(const std::string& str, const std::set& groups) { if (!groups.empty()) { std::cout << "The string '" << str << "' belongs to group(s): "; for (const auto& group : groups) { std::cout << group << " "; } std::cout << std::endl; } else { std::cout << "The string '" << str << "' does not belong to any group." << std::endl; } }

int main() { // Create a map to store sets of group names and their corresponding sets of strings std::map<std::set, std::string> groupsMap;

// Add groups to the map
addGroup(group1, "group1", groupsMap);
addGroup(group2, "group2", groupsMap);

// Test the findGroup function
std::string testString = "banana";
std::set<std::string> groups = findGroup(testString, groupsMap);

// Print the result
printResult(testString, groups);

return 0;

}

anishcana commented 6 months ago

include

include

include

include

include "groups.h"

// Function to check if the string belongs to the first group bool belongsToFirstGroup(const std::string& str, const std::set& group) { return group.find(str) != group.end(); }

int main() { // Test if a string belongs to the first group std::string testString = "banana"; bool belongs = belongsToFirstGroup(testString, Set1);

if (belongs) {
    std::cout << "The string '" << testString << "' belongs to Set1." << std::endl;
} else {
    std::cout << "The string '" << testString << "' does not belong to Set1." << std::endl;
}

return 0;

}

anishcana commented 6 months ago

include

include

include

include

include "groups.h"

// Function to check if the string belongs to the first group bool belongsToFirstGroup(const std::string& str, const std::set& group) { return group.find(str) != group.end(); }

int main() { // Test if a string belongs to the first group std::string testString = "banana"; bool belongs = belongsToFirstGroup(testString, Set1);

if (belongs) {
    std::cout << "The string '" << testString << "' belongs to Set1." << std::endl;
} else {
    std::cout << "The string '" << testString << "' does not belong to Set1." << std::endl;
}

return 0;

}

anishcana commented 6 months ago

bool belongsToFirstGroup(const std::string& str, const std::set& group) { for (const auto& element : group) { if (element == str) { return true; } } return false; }

anishcana commented 6 months ago

include

void checkVoltage(double voltage) { if (voltage < 25) { // Perform operation for low voltage std::cout << "Voltage is low. Performing operation A." << std::endl; } else { // Perform operation for high voltage std::cout << "Voltage is high. Performing operation B." << std::endl; } }

int main() { double voltage; std::cout << "Enter the voltage level: "; std::cin >> voltage;

checkVoltage(voltage);

return 0;

}

anishcana commented 6 months ago

include

void checkPressure(int pressure) { if (pressure >= 50 && pressure < 60) { // Pressure is in the range of 50 to 59 std::cout << "Pressure is low (50-59)." << std::endl; } else if (pressure >= 60 && pressure < 70) { // Pressure is in the range of 60 to 69 std::cout << "Pressure is moderate (60-69)." << std::endl; } else { // Pressure is either below 50 or above 69 std::cout << "Pressure is not within the specified ranges." << std::endl; } }

int main() { int pressure; std::cout << "Enter the pressure level: "; std::cin >> pressure;

checkPressure(pressure);

return 0;

}

anishcana commented 6 months ago

import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException;

import java.io.FileReader; import java.io.FileWriter; import java.io.IOException;

public class JsonToXmlConverter {

public static void main(String[] args) {
    JSONParser parser = new JSONParser();

    try {
        // Parse JSON file
        JSONArray jsonArray = (JSONArray) parser.parse(new FileReader("data.json"));

        // Create XML document
        StringBuilder xmlBuilder = new StringBuilder();
        xmlBuilder.append("<data>\n");
        for (Object obj : jsonArray) {
            JSONObject jsonObject = (JSONObject) obj;
            xmlBuilder.append("\t<dataItem id=\"").append(jsonObject.get("id")).append("\">\n");
            xmlBuilder.append("\t\t<name>").append(jsonObject.get("name")).append("</name>\n");
            xmlBuilder.append("\t\t<value>").append(jsonObject.get("value")).append("</value>\n");
            xmlBuilder.append("\t</dataItem>\n");
        }
        xmlBuilder.append("</data>");

        // Write XML to file
        FileWriter fileWriter = new FileWriter("output.xml");
        fileWriter.write(xmlBuilder.toString());
        fileWriter.close();

        System.out.println("XML file generated successfully.");

    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
}

}

anishcana commented 6 months ago

import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import javax.servlet.http.HttpServletResponse; import java.io.IOException;

@Controller public class ExcelController {

@GetMapping("/exportToExcel")
public void exportToExcel(HttpServletResponse response) throws IOException {
    // Set the response headers
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=table_data.xlsx");

    // Create a new Excel workbook
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("Table Data");

    // Dummy table data (replace with your actual table data)
    Object[][] tableData = {
            {"Name", "Age", "Location"},
            {"John", 30, "New York"},
            {"Alice", 25, "London"},
            {"Bob", 35, "Paris"}
    };

    // Write data to the Excel sheet
    int rowNum = 0;
    for (Object[] rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (Object field : rowData) {
            Cell cell = row.createCell(colNum++);
            if (field instanceof String) {
                cell.setCellValue((String) field);
            } else if (field instanceof Integer) {
                cell.setCellValue((Integer) field);
            }
        }
    }

    // Write workbook to response output stream
    workbook.write(response.getOutputStream());
    workbook.close();
}

}

anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=table_data.xlsx");

    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    workbook.write(response.getOutputStream());
    workbook.close();
}

}

anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=table_data.xlsx");

    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    workbook.write(response.getOutputStream());
    workbook.close();
}

}

anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=table_data.xlsx");

    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    workbook.write(response.getOutputStream());
    workbook.close();
}

}

anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

<!DOCTYPE html>

Export Table to Excel
Name Age Location
John 30 New York
Alice 25 London
anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    response.setContentType("application/vnd.ms-excel");

    // Set the location where the Excel file will be saved
    response.setHeader("Content-Disposition", "attachment; filename=table_data.xlsx"); // This will prompt the user to download the file
    //response.setHeader("Content-Disposition", "inline; filename=table_data.xlsx"); // This will open the file in the browser

    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    workbook.write(response.getOutputStream());
    workbook.close();
}

}

anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    // Specify the directory where you want to save the Excel file
    String directory = "/path/to/save/excel/files";
    // Specify the file name
    String fileName = "table_data.xlsx";

    // Create directory if it doesn't exist
    Path directoryPath = Paths.get(directory);
    if (!Files.exists(directoryPath)) {
        Files.createDirectories(directoryPath);
    }

    // Save the Excel file to the specified location
    try (FileOutputStream fos = new FileOutputStream(directory + "/" + fileName)) {
        workbook.write(fos);
        workbook.close();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

anishcana commented 6 months ago

import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData, HttpServletResponse response) throws IOException {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    int rowNum = 0;
    for (List<String> rowData : tableData) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (String field : rowData) {
            Cell cell = row.createCell(colNum++);
            cell.setCellValue(field);
        }
    }

    // Specify the directory where you want to save the Excel file
    String directory = "/path/to/save/excel/files";
    // Specify the file name
    String fileName = "table_data.xlsx";

    // Create directory if it doesn't exist
    Path directoryPath = Paths.get(directory);
    if (!Files.exists(directoryPath)) {
        Files.createDirectories(directoryPath);
    }

    // Save the Excel file to the specified location
    try (FileOutputStream fos = new FileOutputStream(directory + "/" + fileName)) {
        workbook.write(fos);
        workbook.close();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

anishcana commented 6 months ago

import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody;

import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List;

@Controller public class ExcelController {

@PostMapping("/exportToExcel")
public void exportToExcel(@RequestBody List<List<String>> tableData) {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("TUMMY Data");

    try {
        int rowNum = 0;
        for (List<String> rowData : tableData) {
            Row row = sheet.createRow(rowNum++);
            int colNum = 0;
            for (String field : rowData) {
                Cell cell = row.createCell(colNum++);
                cell.setCellValue(field);
            }
        }

        // Specify the directory where you want to save the Excel file
        String directory = "/path/to/save/excel/files";
        // Specify the file name
        String fileName = "table_data.xlsx";

        // Create directory if it doesn't exist
        Path directoryPath = Paths.get(directory);
        if (!Files.exists(directoryPath)) {
            Files.createDirectories(directoryPath);
        }

        // Save the Excel file to the specified location
        try (FileOutputStream fos = new FileOutputStream(directory + "/" + fileName)) {
            workbook.write(fos);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            workbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

}