Respuesta :
Answer:
Question 1 :Write a program to enter a number and test if it is greater than 45.6 Example:
Answer:
#include <iostream>
using namespace std;
int main()
{
int user_number=0;
cout<<"Enter a number ";
cin >> user_number;
if(user_number >45.6){
cout <<"Greater than 45.6";
}
return 0;
}
Question 2: Test if a number grade is an A (greater than or equal to 90). If so print "Great!"
Answer:
#include <iostream>
using namespace std;
int main()
{
int user_number=0;
cout<<"Enter a number ";
cin >> user_number;
if(user_number >= 90){
cout <<"Great";
}
return 0;
}
Question 3: Test if a password entered is correct. The secret phrase is Ada Lovelace.
Answer:
#include <iostream>
#include <string>
using namespace std;
int main()
{string pass_phrase ="Ada Lovelace";
string user_password="";
cout<<"Enter password ";
getline (cin, user_password);
if(user_password == pass_phrase){
cout <<"Correct";
}
else{
cout <<"Incorrect";
}
return 0;
}
Explanation:
The questions illustrate the use of conditional statements.
Conditional statements are statements whose execution depends on the truth values of a condition.
The three programs are written in Python, and comments are used to explain each line of the programs.
Question 1: Test if it is greater than 45.6
#This gets the number from the user
num = float(input("Number: "))
#This tests if the user input is greater than 45.6
if num > 45.6:
#If yes, this prints greater than
print(num,"is greater than 45.6")
#If otherwise,
else:
#This prints not greater than
print(num,"is not greater than 45.6")
Question 2: Test if a number grade is an A (greater than or equal to 90). If so print "Great!"
#This gets the grade from the user
grade = int(input("Grade: "))
#This tests if the user input is 90 and above
if grade >= 90:
#If yes, this prints Great!
print("Great!")
Question 3: Test if a password entered is correct. The secret phrase is Ada Lovelace.
#This gets the password from the user
password = input("Grade: ")
#This tests if the password is correct
if password == "Ada Lovelace":
#If yes, this prints Correct!
print("Correct!")
#If otherwise,
else:
#this prints Incorrect!
print("Incorrect!")
Read more about similar programs at:
https://brainly.com/question/13788221