
enum Input
{
A
{
@Override
int[] getArray() {
return new int[]{1,1,1,1,0,0,0,0};
}
},
B
{
@Override
int[] getArray() {
return new int[]{1,1,0,0,1,1,0,0};
}
},
C
{
@Override
int[] getArray() {
return new int[]{1,0,1,0,1,0,1,0};
}
},
F
{
@Override
int[] getArray() {
return new int[]{0,0,0,0,0,0,0,0};
}
},
T
{
@Override
int[] getArray() {
return new int[]{1,1,1,1,1,1,1,1};
}
};
abstract int[] getArray();
}
class Propositions
{
static int[] arr1;
static int[] arr2;
static int[] current=new int[]{0,0,0,0,0,0,0,0};
static int[] prev=new int[]{0,0,0,0,0,0,0,0};
public static void main(String[] args)
{
boolean exitFlag=false;
Scanner sc=new Scanner(System.in);
String input1,input2;
while(!exitFlag)
{
System.out.println("Simple propositional calculator\n1.Negation\n2.Conjunction\n3.Disjunction\n4.Implication\n5.Equivalence\n6.Quit");
int choice=sc.nextInt();
switch (choice)
{
case 1:
System.out.println("Enter a number from A,B,C,F,T,R,M:");
input1=sc.next();
if(input1.equals("R"))
{
current=negation(current);
}
else if(input1.equals("M"))
{
current=negation(prev);
}
else
{
current=negation(Input.valueOf(input1).getArray());
}
prev=current; //for next iteration
break;
case 2:
System.out.println("Enter 2 numbers from A,B,C,F,T,R,M:");
input1=sc.next();
input2=sc.next();
assignActualArguments(input1,input2);
current=conjunction(arr1,arr2);
prev=current; //for next iteration
break;
case 3:
System.out.println("Enter 2 numbers from A,B,C,F,T,R,M:");
input1=sc.next();
input2=sc.next();
assignActualArguments(input1,input2);
prev=current; //for next iteration
break;
case 4:
System.out.println("Enter 2 numbers from A,B,C,F,T,R,M:");
input1=sc.next();
input2=sc.next();
assignActualArguments(input1,input2);
prev=current; //for next iteration
break;
case 5:
System.out.println("Enter 2 numbers from A,B,C,F,T,R,M:");
input1=sc.next();
input2=sc.next();
assignActualArguments(input1,input2);
prev=current; //for next iteration
break;
case 6:
exitFlag=true;
break;
}
}
sc.close();
}
public static int[] negation(int[] arr)
{
int[] res=new int[arr.length];
for(int i=0;i<arr.length;i++)
{
res[i]=arr[i]^1;
}
System.out.println(Arrays.toString(res));
return res;
}
public static int[] conjunction(int[] arr1,int[] arr2)
{
int[] res=new int[arr1.length];
for(int i=0;i<arr1.length;i++)
{
res[i]=arr1[i]|arr2[i]; //bitwise or
}
System.out.println(Arrays.toString(res));
return res;
}
public static int[] disjunction(int[] arr1,int[] arr2)
{
int[] res=new int[arr1.length];
for(int i=0;i<arr1.length;i++)
{
res[i]=arr1[i]&arr2[i];
}
System.out.println(Arrays.toString(res));
return res;
}
public static int[] implication(int[] arr1,int[] arr2)
{
int[] res=new int[arr1.length];
for(int i=0;i<arr1.length;i++)
{
res[i]=arr1[i]==1 && arr2[i]==0?0:1; //based on truth table of implication
}
System.out.println(Arrays.toString(res));
return res;
}
public static int[] equivalence(int[] arr1,int[] arr2)
{
int[] res=new int[arr1.length];
for(int i=0;i<arr1.length;i++)
{
res[i]=(arr1[i]==1 && arr2[i]==1) ||(arr1[i]==0 && arr2[i]==0)?1:0; //based on truth table of equivalence
}
System.out.println(Arrays.toString(res));
return res;
}
public static void assignActualArguments(String s1,String s2)
{
if(s1.equals("R"))
{
arr1=current;
}
else if(s1.equals("M"))
{
arr1=prev;
}
else
{
arr1=Input.valueOf(s1).getArray();
}
if(s2.equals("R"))
{
arr2=current;
}
else if(s2.equals("M"))
{
arr2=prev;
}
else
{
arr2=Input.valueOf(s2).getArray();
}
}
}
Write a program that generates a simple three statement calculator. It should display the following menu:...
(PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...
extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...
Note: You must write this program in Python. General Requirements The program should display a menu and allow the user to perform one of the following tasks. Add an item to the list Delete an item from the list Print the list Print the list in reverse Quit the program The program should run until the user chooses to quit. In Python, programmatically quitting the application is achieved with the exit() procedure. You should use a List to store the...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
Python 3.7 to be used. Just a simple design a program
that depends on its own. You should also not need to import
anything. No code outside of a function!
Median List Traversal and Exception Handling Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options 50% below 50% above Add a number to the list/array...
Java only please Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Triangle 3. Calculate the Area of a Rectangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula: area = ∏r2 Use 3.14159 for ∏. If the user enters 2 the program should ask for...
Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...
Write a C++ program that shows the following menu options and lets the user to convert from Metric to Imperial system: Converter Toolkit -------------------- 1. Temperature Converter 2. Distance Converter 3. Weight Converter 4. Quit If the user enters 1, the program should ask for the temperature in Celsius and convert it to Fahrenheit If the user enters 2, the program should ask for the distance in Kilometer and convert it to Mile If the user...
Write a C++ program that will display the following menu and work accordingly. A menu that will display the following choices and uses functions to carry out the calculations: 1. Call a function named classInfo() to ask the user the number of students and exams in a course. 2. Call a function getGrade() that will get the information from classInfo() and asks the user to enter the grades for each student. 3. Call a function courseGrade() to display the average...
Edit, compile, and run the following programs on the UNIX shell: Write a program that takes in six commandline arguments and has four functions (described below) that use bitwise operators. The user should enter six space-separated commandline arguments: four characters (any ASCII character) followed by two integers. Anything else should print an error message telling the user what the correct input is and end the program. Convert the commandline input into "unsigned char" and "unsigned int" datatypes. Be careful with...