diff --git a/Calculators/Cyclomatic-Complexity-Calculator/README.md b/Calculators/Cyclomatic-Complexity-Calculator/README.md new file mode 100644 index 000000000..acb810cd7 --- /dev/null +++ b/Calculators/Cyclomatic-Complexity-Calculator/README.md @@ -0,0 +1,29 @@ +#

Cyclomatic Complexity Calculator

+ +## Description :- + +Calculates the cyclomatic complexity using three different methods. + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Features :- + +- Calculates cyclomatic complexity based on number of nodes, components and edges in graph. +- Calculates cyclomatic complexity using regions of graph. +- Calculates cyclomatic complexity using conditional nodes of graph. +- Gives clear and detailed input instructions. + +## Screenshots :- + +### Method 1 +![image](https://github.com/user-attachments/assets/9793ab3f-262b-4423-88df-feaed376a066) + +### Method 2 +![image](https://github.com/user-attachments/assets/687b8330-12e3-4b3a-af08-dc9dc179c24f) + +### Method 3 +![image](https://github.com/user-attachments/assets/57b72654-01f4-47ef-8f91-65d2c9a50cc2) diff --git a/Calculators/Cyclomatic-Complexity-Calculator/index.html b/Calculators/Cyclomatic-Complexity-Calculator/index.html new file mode 100644 index 000000000..f5cdb978f --- /dev/null +++ b/Calculators/Cyclomatic-Complexity-Calculator/index.html @@ -0,0 +1,65 @@ + + + + + + + + Cyclomatic Complexity Calculator + + + +

Cyclomatic Complexity Calculator

+ +
+ + + + + + + +
+

Calculation of Cyclomatic calculation using Number of nodes, edges and connected components

+ + + + + + + +

+ + +
+ +
+

Calculation of Cyclomatic calculation using Number of closed regions in the graph

+ + + +

+ + +
+ +
+

Calculation of Cyclomatic calculation using Number of condition nodes

+ + + + Including default case + + + Excluding switch case node + + +

+ + +
+
+ + + + \ No newline at end of file diff --git a/Calculators/Cyclomatic-Complexity-Calculator/script.js b/Calculators/Cyclomatic-Complexity-Calculator/script.js new file mode 100644 index 000000000..2b1065770 --- /dev/null +++ b/Calculators/Cyclomatic-Complexity-Calculator/script.js @@ -0,0 +1,117 @@ +// Method 1 +// Calculation of Cyclomatic calculation using Number of nodes, edges and connected components + +function method1() { + let components = document.getElementById("components").value.trim(); + let nodes = document.getElementById("nodes").value; + let edges = document.getElementById("edges").value; + if (components == '' || edges == '' || nodes == '') { + let output1 = "All fields are mandatory"; + document.getElementById("output1").innerHTML = output1; + } else if (components < 0 || nodes < 0 || edges < 0) { + let output1 = "Enter only positive numbers"; + document.getElementById("output1").innerHTML = output1; + } else { + components = parseInt(components); + nodes = parseInt(nodes); + edges = parseInt(edges); + let output1 = edges - nodes + (2 * components); + document.getElementById("output1").innerHTML = output1; + } +} + +// clear input for method1 +function clearInputs1() { + const inputs = document.querySelectorAll('.clearable1'); + inputs.forEach(input => input.value = ''); + const output = document.getElementById("output1"); + output.innerHTML = ''; +} + +// Method 2 +// Calculation of Cyclomatic calculation using Number of closed regions in the graph + +function method2() { + let region_number = document.getElementById("regions").value; + if (region_number == '') { + let output2 = "All fields mandatory"; + document.getElementById("output2").innerHTML = output2; + } else if (region_number < 0) { + let output2 = "Enter only positive numbers"; + document.getElementById("output2").innerHTML = output2; + } else { + region_number = parseInt(region_number); + let output2 = region_number + 1; + document.getElementById("output2").innerHTML = output2; + + } +} + +// clear input for method2 +function clearInputs2() { + const inputs = document.querySelectorAll('.clearable2'); + inputs.forEach(input => input.value = ''); + const output = document.getElementById("output2"); + output.innerHTML = ''; +} + +// Method 3 +// Calculation of Cyclomatic calculation using Number of condition nodes +function method3() { + let choice = document.getElementById("switch-case").value.trim(); + let res = choice.toLowerCase(); + if (res == "yes") { + let casecount = document.getElementById("case-count").value; + let nodecount = document.getElementById("node-count").value; + if (casecount == '' || nodecount == '') { + let output3 = "All fields are mandatory"; + document.getElementById("output3").innerHTML = output3; + } else if (casecount < 0 || nodecount < 0) { + let output3 = "Enter only positive numbers"; + document.getElementById("output3").innerHTML = output3; + } else { + nodecount = parseInt(nodecount); + casecount = parseInt(casecount); + let output3 = nodecount + (casecount - 1) + 1; + document.getElementById("output3").innerHTML = output3; + } + } else if (res == "no") { + let nodecount = document.getElementById("node-count").value; + if (nodecount == '') { + let output3 = "All fields are mandatory"; + document.getElementById("output3").innerHTML = output3; + } else if (nodecount < 0) { + let output3 = "Enter only positive numbers"; + document.getElementById("output3").innerHTML = output3; + } else { + nodecount = parseInt(nodecount); + let output3 = nodecount + 1; + document.getElementById("output3").innerHTML = output3; + } + } else { + let output3 = "Please enter 'yes' or 'no' for the switch case question"; + document.getElementById("output3").innerHTML = output3; + } +} + +// Function to hide input field when switch case condition is false in Method 3 +function checkSwitchCase() { + var choice = document.getElementById("switch-case").value.trim(); + let res = choice.toLowerCase(); + if (res == "yes" || res == 'y') { + document.getElementById("case-count").style.display = "block"; + document.getElementById("case-count-text").style.display = "block"; + } else { + document.getElementById("case-count").style.display = "none"; + document.getElementById("case-count-text").style.display = "none"; + document.getElementById("note").style.display = "none"; + } +} + +// clear input for method3 +function clearInputs3() { + const inputs = document.querySelectorAll('.clearable3'); + inputs.forEach(input => input.value = ''); + const output = document.getElementById("output3"); + output.innerHTML = ''; +} \ No newline at end of file diff --git a/Calculators/Cyclomatic-Complexity-Calculator/style.css b/Calculators/Cyclomatic-Complexity-Calculator/style.css new file mode 100644 index 000000000..a7ed3be94 --- /dev/null +++ b/Calculators/Cyclomatic-Complexity-Calculator/style.css @@ -0,0 +1,271 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + display: flex; + justify-content: center; + align-items: center; + height: 100%; + min-height: 100vh; + flex-direction: column; + color: #fff; + font-family: 'Arial', sans-serif; + background: linear-gradient(-60deg, #F765A3, #A155B9, #165BAA, #0B1354); +} + +section { + margin-top: 5vh; + width: 90%; + max-width: 90vh; + display: inline; + flex-direction: column; + align-items: center; + min-height: auto; + background-color: rgba(255, 255, 255, 0.1); + padding: 20px; + margin-bottom: 50px; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1 { + font-weight: bolder; + font-size: 3em; + margin: 35px 0; + text-align: center; +} + +h2 { + font-size: 1.5em; + margin-bottom: 20px; + text-align: center; +} + +input[type="radio"] { + display: none; +} + +div.tab-content { + background-color: rgba(255, 255, 255, 0.2); + border-radius: 10px; + overflow: hidden; + padding: 20px; + display: none; + flex-direction: column; + align-items: center; + width: 100%; + margin-bottom: 20px; +} + +label { + padding: 10px 20px; + display: inline; + flex-direction: column; + background-color: #F9D1D1; + border-radius: 5px; + flex-direction: column; + color: #000; + cursor: pointer; + font-size: 1.2rem; + transition: .4s; + margin: 10px 0; + text-align: center; +} + +.tab-content { + display: none; + margin: 1em 0; + height: auto; +} + +.tab-content .label-text { + font-size: 1.2rem; + color: #fff; +} + +input[type="radio"]:checked+label { + background-color: #FFA4B6; + color: #fff; +} + +#tab1:checked~#content1, +#tab2:checked~#content2, +#tab3:checked~#content3 { + display: flex; +} + +button { + margin: 15px 0; + width: 100%; + max-width: 300px; + padding: 10px; + border-radius: 8px; + border: none; + display: block; + font-size: 1.2rem; + font-family: 'Times New Roman', Times, serif; + font-weight: bold; + cursor: pointer; + background-color: #fff; + color: #000; + transition: background-color 0.3s, color 0.3s; +} + +button:hover { + background-color: #FFA4B6; + color: #fff; +} + +input::-webkit-outer-spin-button, +input::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; +} + +input { + display: block; + border: none; + line-height: 22px; + padding: 10px; + font-size: 1rem; + border-radius: 5px; + width: 100%; + max-width: 300px; + margin: 10px 0; + text-align: center; +} + +.tab-content label { + padding: 0; + font-size: 1rem; + background-color: transparent; + display: block; + color: #fff; +} + +.note { + margin-bottom: 5px; + font-size: 0.9rem; + color: #fff; +} + +span { + display: block; + color: #fff; +} + +@media (max-width: 768px) { + h1 { + font-size: 2.5rem; + } + + h2 { + font-size: 1.2rem; + } + + label { + font-size: 1rem; + padding: 8px 15px; + } + + button { + margin: 10px 0; + padding: 8px 20px; + font-size: 1rem; + width: 90%; + } + + input[type="number"], + input[type="text"] { + font-size: 1rem; + height: 2.5vmax; + padding-left: 2vmax; + padding-right: 2vmax; + padding-top: 2vmax; + padding-bottom: 2vmax; + } + + .tab-content { + padding: 5px; + } + + .tab-content .label-text { + font-size: 1rem; + } +} + +@media (max-width: 590px) { + h1 { + font-size: 2rem; + } + + h2 { + font-size: 1.5rem; + } + + label { + font-size: 0.9rem; + padding: 6px 10px; + margin-bottom: 2px; + } + + button { + margin: 8px 0; + padding: 8px 18px; + font-size: 0.9rem; + width: 90%; + } + + input[type="number"], + input[type="text"] { + font-size: 1rem; + height: 2.5vmax; + padding-left: 2vmax; + padding-right: 2vmax; + padding-top: 2vmax; + padding-bottom: 2vmax; + } + + .tab-content { + padding: 8px; + } +} + +@media (max-width: 400px) { + h1 { + font-size: 1.5rem; + } + + h2 { + font-size: 1.2rem; + } + + label { + font-size: 0.8rem; + padding: 4px 10px; + } + + button { + margin: 5px 0; + padding: 6px 15px; + font-size: 0.8rem; + width: 90%; + } + + input[type="number"], + input[type="text"] { + font-size: 1rem; + height: 2.5vmax; + padding-left: 2vmax; + padding-right: 2vmax; + padding-top: 2vmax; + padding-bottom: 2vmax; + } + + .tab-content { + padding: 5px; + } +} \ No newline at end of file diff --git a/calculators.json b/calculators.json index bac64ecfc..2d96b14f7 100644 --- a/calculators.json +++ b/calculators.json @@ -617,6 +617,12 @@ "link": "./Calculators/Cut-Off-Calculator/index.html", "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Cut-Off-Calculator" }, + { + "title": "Cyclomatic Complexity Calculator", + "description": "Calculates the cyclomatic complexity of the program.", + "link": "./Calculators/Cyclomatic-Complexity-Calculator/index.html", + "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Cyclomatic-Complexity-Calculator" + }, { "title": "DTI Ratio Calculator", "description": "Calculates your debt-to-income ratio, to help in managing your financial health.",