Applying the three programming languages (java,python&c++), Study Guides, Projects, Research of Programming Languages

This is a document that will serve as your guide to create a code that uses all three of the programming languages named java, python & c++

Typology: Study Guides, Projects, Research

2021/2022

Available from 02/07/2024

barce-2
barce-2 🇵🇭

2 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1.Astronomy Helper
Create an application that displays the following menu:
Select a Planet
1. Mercury
2. Venus
3. Earth
4. Mars
5. Exit the program
Enter your selection.
When the user selects a planet from the menu, the program should display data about the
planet’s
average distance from the sun, the planet’s mass, and the planet’s surface temperature.
2. Password Weakness Detector
Design a program that asks the user to enter a password, and then analyzes the password for the
following weaknesses:
Fewer than 8 characters
Does not contain at least one uppercase letter and one lowercase letter
Does not contain at least one numeric digit
Does not contain at least one special character (a character that is not a letter or a
numeric digit)
Is a sequence of consecutive uppercase letter s (such as ABCDE)
Is a sequence of consecutive lowercase letters (such as abcde)
Is a sequence of consecutive numeric digits (such as 12345)
Is a repeating sequence of characters (such as ZZZZZ or 55555)
The program should display messages indicating whether any of these weaknesses are found
in the password.
3. Recursive Power Method
Design a function that uses recursion to raise a number to a power. The function should accept
two
arguments: the number to be raised and the exponent. Assume that the exponent is a
nonnegative
integer.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Applying the three programming languages (java,python&c++) and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity!

1.Astronomy Helper Create an application that displays the following menu: Select a Planet

_1. Mercury

  1. Venus
  2. Earth
  3. Mars
  4. Exit the program Enter your selection._ When the user selects a planet from the menu, the program should display data about the planet’s average distance from the sun, the planet’s mass, and the planet’s surface temperature. 2. Password Weakness Detector Design a program that asks the user to enter a password, and then analyzes the password for the following weaknesses:
    • Fewer than 8 characters
    • Does not contain at least one uppercase letter and one lowercase letter
    • Does not contain at least one numeric digit
    • Does not contain at least one special character (a character that is not a letter or a numeric digit)
    • Is a sequence of consecutive uppercase letters (such as ABCDE)
    • Is a sequence of consecutive lowercase letters (such as abcde)
    • Is a sequence of consecutive numeric digits (such as 12345)
    • Is a repeating sequence of characters (such as ZZZZZ or 55555) The program should display messages indicating whether any of these weaknesses are found in the password. 3. Recursive Power Method Design a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer.

PROBLEM ONE: JAVA, PYTHON, C++

PROBLEM THREE: JAVA, PYTHON, C++

CODES

PROBLEM ONE:

JAVA

import java.util.Scanner; public class Main { public static void main(String[] args) { int menuSelection = 0; do { // Display the menu and get the user's selection menuSelection = displayMenu(); // Display the information for the user's selection switch (menuSelection) { case 1: printPlanet("MERCURY", "57.9", "3.31 x 10^23", "-173 to 430"); break; case 2: printPlanet("VENUS", "108.2", "4.87 x 10^24", "472"); break; case 3: printPlanet("EARTH", "149.6", "5.967 x 10^24", "-50 to 50"); break; case 4: printPlanet("MARS", "227.9", "0.6424 x 10^24", "-140 to 20"); break;

while (menuSelection != 5); } // Call the displayMenu method to display the menu options and get the // user's selection public static int displayMenu() { System.out.println("Please select a planet to view details about it's: "); System.out.println("average distance from the sun, mass, and surface temperature."); System.out.println("_________________________________________________________"); System.out.println("1. Mercury"); System.out.println("2. Venus"); System.out.println("3. Earth"); System.out.println("4. Mars"); System.out.println("5. EXIT the program"); System.out.println("Enter your selection: "); Scanner keyboard = new Scanner(System.in); int menuSelection = keyboard.nextInt(); // Validate the menu selection while (menuSelection < 1 || menuSelection > 5) { System.out.print("This is an invalid selection."); System.out.print("Enter a selection from 1-5: "); menuSelection = keyboard.nextInt(); } return menuSelection; } public static void printPlanet(String planet, String distanceToSun, String mass, String degrees) {

condition = menuSelection != 5 while (menuSelection != 5): def displayMenu(): print("Please select a planet to view details about it's: ") print("average distance from the sun, mass, and surface temperature.") print("_________________________________________________________") print("1. Mercury") print("2. Venus") print("3. Earth") print("4. Mars") print("5. EXIT the program") print("Enter your selection: ") while menuSelection < 1 or menuSelection > 5: print("This is an invalid selection.", end = '') print("Enter a selection from 1-5: ", end = '') def printPlanet(planet, distanceToSun, mass, degrees): print("\t\t\t " + planet) print("_________________________________________________________") print("Average Distance from the sun: " + distanceToSun + " million kiometers") print("Mass: " + mass + " kg") print("Surface Temperature: " + degrees + " degrees Celsius") print("_________________________________________________________") C++

#include #include #include class Settlement { public: template < typename T > static T input() { T value; std::cin >> value; return value; } }; class Main { public: static void main(std::vector<std::string> &args) { int menuSelection = 0; do { // Display the menu and get the user's selection menuSelection = Main::displayMenu(); // Display the information for the user's selection switch (menuSelection){ case 1: Main::printPlanet("MERCURY", "57.9", "3.31 x 10^23", "-173 to 430"); break; case 2: Main::printPlanet("VENUS", "108.2", "4.87 x 10^24", "472"); break;

return menuSelection; } static void printPlanet(std::string planet, std::string distanceToSun, std::string mass, std::string degrees) { std::cout << "\t\t\t " + planet << std::endl; std::cout << "_________________________________________________________" << std::endl; std::cout << "Average Distance from the sun: " + distanceToSun + " million kiometers" << std::endl; std::cout << "Mass: " + mass + " kg" << std::endl; std::cout << "Surface Temperature: " + degrees + " degrees Celsius" << std::endl; std::cout << "_________________________________________________________" << std::endl; } }; int main(int argc, char **argv){ std::vector<std::string> parameter(argv + 1, argv + argc); Main::main(parameter); return 0; };

PROBLEM TWO:

JAVA

import java.util.Scanner; public class Main { public static void main(String[] args) { int passwordLength=8, upChars=0, lowChars=0; int special=0, digits=0; char ch; Scanner s = new Scanner(System.in); System.out.println("----Direction to Create a Password----"); System.out.println("1. The Password must be at least 8 characters long."); System.out.println("2. The Password must contain at least one uppercase character."); System.out.println("3. The Password must contain at least one lowercase character."); System.out.println("4. The Password must contain at least one digit (0-9)."); System.out.println("5. The Password must contain at least one special characters."); System.out.println("6. The Password must not contain < or >."); System.out.print("\nCreate a Password: "); String password = s.nextLine(); int total = password.length(); if(total<passwordLength) { System.out.println("\nThe Password's Length has to be of 8 characters or more."); return;

else { System.out.println("\nThe Strength of Password is Medium."); } System.out.println("\n----The Password Contains----"); System.out.println("UpperCase Character: " +upChars); System.out.println("LowerCase Character: " +lowChars); System.out.println("Digit: " +digits); System.out.println("Special Character: " +special); } else { if(upChars==0) System.out.println("\nThe Password must contain at least one uppercase character."); if(lowChars==0) System.out.println("\nThe Password must contain at least one lowercase character."); if(digits==0) System.out.println("\nThe Password must contain at least one digit."); if(special==0) System.out.println("\nThe Password must contain at least one special character."); } } } PYTHON import re v=input("Enter the password:") if(len(v)>=8): if(bool(re.match('((?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[!@#$%^&*]).{8,30})',v))==True):

print("The password is strong") elif(bool(re.match('((\d)([a-z])([A-Z])([!@#$%^&]*).{8,30})',v))==True): print("The password is weak") else: print("You have entered an invalid password.") C++ #include using namespace std; void printStrongNess(string& input) { int n = input.length(); // Checking lower alphabet in string bool hasLower = false, hasUpper = false; bool hasDigit = false, specialChar = false; string normalChars = "abcdefghijklmnopqrstu" "vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "; for (int i = 0; i < n; i++) { if (islower(input[i])) hasLower = true; if (isupper(input[i])) hasUpper = true; if (isdigit(input[i])) hasDigit = true; size_t special = input.find_first_not_of(normalChars); if (special != string::npos) specialChar = true; } // Strength of password cout << "Strength of password:-"; if (hasLower && hasUpper && hasDigit &&

return (base * power(base, powerRaised - 1)); } else { return 1; } } } PYTHON def power(base,exp): if(exp==1): return(base) if(exp!=1): return(base*power(base,exp-1)) base=int(input("Enter base: ")) exp=int(input("Enter exponential value: ")) print("Result:",power(base,exp)) C++ #include using namespace std; int calculatePower(int, int); int main() { int base, powerRaised, result; cout << "Enter base number: ";

cin >> base; cout << "Enter power number(positive integer): "; cin >> powerRaised; result = calculatePower(base, powerRaised); cout << base << "^" << powerRaised << " = " << result; return 0; } int calculatePower(int base, int powerRaised) { if (powerRaised != 0) return (base*calculatePower(base, powerRaised-1)); else return 1; }