Professional Documents
Culture Documents
> problem 3:
1 e
> problem 4:
compile time error a
> problem 5:
0-1 a
> preoblem 6:
1-1 d
> problem 7:
123 c
>problem 8:
x is tested first, then decremented to (0)
a
> problem 9:
a) First character in Aly is capital
>Problem 12:
compile time error, variable g is defined twice
>> exercise Two:
> Problem One:
#include <iostream>
#include<string.h>
using namespace std;
int main() {
//Define 2 string objects, and get their values from the user using the
//cin command only (not getline()).
string str1, str2;
cin >> str1 >> str2;
if (firstChCap) {
cout << "The statemt starts by capital letters";
}
return 0;
}
> Problem Two:
//Mini Calculator program.
#include <iostream>
using namespace std;
int main() {
//Define two float variables a and b; and get their values from the user.
float a, b;
cout << "Enter two integer values" << endl;
cin >> a >> b;
//Define a character x;
char x;
//Define a boolean variable “authenticated”, and get its value from the
//user.
bool authenticated;
cout << "enter either 0 or one" << endl;
cin >> authenticated;
//If the value of authenticated is true; then print a welcome message to the
//user.
if (authenticated) {
cout << "Hi wasssssup!" << endl;
cout << "this is a calculator app" << endl;
//Ask the user to enter the value of character x; such that the user
must
//enters either ‘+’ or ‘-’ only.
cout << "Enter either + or - " << endl;
cin >> x;
//If the user enters ‘+’, then prints a + b.
if (x == '+') {
cout << "a + b = ";
cout << a + b;
}
//If the user enters ‘-’, then prints a - b.
else if (x == '-') {
cout << "a - b = ";
cout << a - b;
}
return 0;
}
>> Exercise 3:
> problem one:
false 0
false 0
True 1
True 1
False 0
False 0
true 1
False 0
True 1
True 1
False 0
True 1
True 1
True 1
# include <iostream>
using namespace std;
int main(){
bool isPrep = 0;
double mark;
cout << "Enter 1 if you are prep or 0 if you are not" << endl;
cin >>isPrep;
cout << "what is your grade" << endl;
cin >> mark;
if(mark >= 50&& mark <=100 ){
cout << "you passed prep year, congratulations" << endl;
}
else
cout << "you have not passed";
}
int main(){
int age, numOfBrothers, numOfFriends;
cout << "input the following consecutively age, numOfBrothers, numOfFriends" <<
endl;
cin >> age >> numOfBrothers >> numOfFriends;
//if age is even number print “Your age is even.”.
if (age %2 != 0){
cout << "your age is even" << endl;
}
if (numOfBrothers %2 != 0){
cout << "you have an odd number of brothers" << endl;
}
if (numOfFriends > 2 && numOfFriends <4 ){
cout << "wow you have a lot of friends" << endl;
}