Open anishcana opened 6 months ago
// Function to add a group to the groups map
void addGroup(const std::set
// Function to find which group(s) the string belongs to
std::set
// Function to print the result
void printResult(const std::string& str, const std::set
int main() {
// Define sets of strings representing different groups
std::set
// 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;
}
// Function to add a group to the groups map
void addGroup(const std::set
// Function to find which group(s) the string belongs to
std::set
// Function to print the result
void printResult(const std::string& str, const std::set
int main() {
// Create a map to store sets of group names and their corresponding sets of strings
std::map<std::set
// 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;
}
extern const std::set
const std::set
// Function to add a group to the groups map
void addGroup(const std::set
// Function to find which group(s) the string belongs to
std::set
// Function to print the result
void printResult(const std::string& str, const std::set
int main() {
// Create a map to store sets of group names and their corresponding sets of strings
std::map<std::set
// 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;
}
// Function to check if the string belongs to the first group
bool belongsToFirstGroup(const std::string& str, const std::set
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;
}
// Function to check if the string belongs to the first group
bool belongsToFirstGroup(const std::string& str, const std::set
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;
}
bool belongsToFirstGroup(const std::string& str, const std::set
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;
}
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;
}
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();
}
}
}
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();
}
}
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();
}
}
<!DOCTYPE html>
Name | Age | Location |
---|
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();
}
}
<!DOCTYPE html>
Name | Age | Location |
---|
<!DOCTYPE html>
Name | Age | Location |
---|
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();
}
}
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
<!DOCTYPE html>
Name | Age | Location |
---|---|---|
John | 30 | New York |
Alice | 25 | London |
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();
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
}
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"};
}