You are on page 1of 5

>> lab 7

>> exercise one

> problem one:


011 c

> problem two


3 c

> 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 10:


011 b

> problem 11:


25 c

>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;

//Define a boolean variables eqInSize, and firstChCap.


bool eqInSize, firstChCap =0, firstChCap1=0, firstChCap2=0;

//Test if the number of characters in the two strings are equal.


//Then assign the result of testing to the variable eqInSize (true if
//equal).
if (str1.size() == str2.size()) {
//Test if the first character in the two string objects is capital.
Then
//assign the result of testing to the variable firstChCap (true if both
//letters are capitals or only one is capital).
eqInSize = true;
if (str1[0] >= 65 && str1[0] < 97) {
firstChCap1 = true;
}
if (str2[0] >= 65 && str2[0] < 97) {
firstChCap2 = true;
}
if (firstChCap1 || firstChCap2) {
firstChCap = true;
}
cout << "Equal in size" << endl;

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

> problem two:

>> Exercise Four:

> Problem (1): Follow these steps to write a C++ program:


Instruction 1: Define a variables isPrep of datatype boolean and initialize its
value to false.
Instruction 2: Define one variable of type double mark.
Instruction 3: Ask the user to enter the text “true” if he is a prep year student.
Instruction 4: Assign true to the variable isPrep if he enters “true”.
Instruction 5: Ask the user to enter the value of mark. The user must enter the
value between 0
and 100 only.
Instruction 6: if the user inputs a mark greater than 50 and less than 100, print
to the user “you
passed prep year, congratulations”

# 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";
}

> problem two:

Problem (2): Follow these steps to write a C++ program:


Instruction 1: Define three integer variables age, numOfBrothers and numOfFriends.
Instruction 2: Get their values from the user.
Instruction 3: if age is even number print “Your age is even.”.
Instruction 4: if numOfBrothers is odd number print “Your odd number of brothers.”.
Instruction 5: if numOfFriends is greater than 2 and less than 4, “you got many
friends.”.
#include <iostream>
using namespace std;

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;
}

> Problem (3): Follow these steps to write a C++ program:


Instruction 1: Define three integer variables a, b and c.
Instruction 2: Get values of these integers from the user, such that the user is
instructed to enter
positive values not greater than 10.
Instruction 3: Define another two integer variables max, min, and initialize max to
-1, and
initialize min to 10.
Instruction 4: Print out the values of the variables a, b and c, but in ascending
order. {You should
use only if condition (without else statement) and should also use the variables
max and min.}

You might also like