How would we output something to the user and get input from the user.
cout << "outputs to user";
cin >> inputUserData;
A programmable machine designed to follow instructions is?
Computer
How many bytes are in a char
char x = 'A';
1 Byte
will this if statement execute? Given: x =2;
if(x==2){
cout << "hello";
}
yes it will output hello.
if(Expression is true){
statement;
}
What is the pre processor directive of a program?
#include <iostream>
Remember #includes dont have ;
What is the keyword to format the width of a cout statement.
cout << setw();
setw() lets us set the width of output
This retrieves and decodes program instructions, its part of the CPU
Control Unit
What's the ASCII value of A
-keep in mind uppercase A and lowercase a have different ASCII values
65
Will this run?
int x =3;
if(x= 4){
cout << "Hello";
}
Yes it will output hello.
So question is why?
Because in the if() we let x new value be 4
instead of asking if x == 4.
What's the difference between Procedural programming and OOP (object-oriented-programming)
Procedural programming focuses on the process and functions to process data.
OOP focuses on objects working together to manipulate data.
Using the #include <iomanip> header file, how can we set the decimal places to 4 of a variable?
Assume double x = 3.333365;
cout << fixed << showpoint << setprecision(4);
its a hardware on CPU optimized for high speed calculations and true/false logic
Arithmetic and Logic unit
How can I cast only one type of datatype if i wish to do so.
Ex: lets say i have int x =5; and double y = 5.5;
I want x+y to be casted as an int
static_cast<int>
so when u do x+y it'll be 10.
Whats the output?
int x = 10;
if(x == 1){
cout <<"A" << endl;
}
else if(x == 9){
cout << "B" << endl;
}
else{
cout << "C" << endl;
}
The correct answer is C
The keyword sizeof() does what?
Also how many bytes of data are in a int?
sizeof() checks the byte of a variable
int has 4 bytes.
What are the three outputs of the following.
int x = 0;
while(x < 3){
cout << ++x;
}
Solution :
1
2
3
This is volatile(Temporary) and is erased when the computer is not on.
Main Memory (RAM)
Type Coercion Promotion is when you...
You convert to a higher datatype.
Example:
cout << 50.5 + 50;
This outputs 100.50 since double is greater than int.
Is this code okay? Given x = 1;
switch(x){
case 1: cout << "hello" << endl;
case 5: cout << "answer was 5" ;
}
Yes, there is something wrong.
since we did not put a break statement the program keeps on going.
What does PEMDAS stand for?
How does the computer execute code (which direction)?
Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction.
From Left to Right
----------->
What are the two ways we can go to the next line in our console output.
cout << endl;
OR
cout << "\n";
What is a Literal?
its a value written into the program. Like the name suggests a literal does not have a variable.
Example:
cout << 12; both 12 and "hi" are literals
cout << "hi"
This datatype is used as a flag it can represent 1 or 0.
Bool
Declare: bool x = true for 1; false for 0
What numbers are allowed
if( x > 0 && x <101){
if(x != 55){ cout << "Hello" ;}
}
numbers from 1 to 100 can be executed with the loop
However u cannot have 55
cout << 12/3*10 << endl;
cout << 10*3/12;
40
2.5