class notes
class notes
Main components
CPU
Ram
bias-tell where the data I or the os is.
Firmware- hardware and software together
Pose- power on self test
Instruction-input the actions and address for the data
Computer software- collections of programs
Classes of computers
Pc
Workstation
Server level- too powerful
Network
Tcpip protocol
Computers and devices connected to each other
Comp. organizations
Cpu,gpu,memory,storage,motherboard,psu,i/o-main 5 components
Code
#include <iostream>-----library
using namespace std;
int main() {
cout<<"Hello World";-----print
return 0;-------tell the function about the result of the function
}
Class – blueprint
Encapsulation is making some of the data invisible which is not needed in the main program(me)
Polymorphism – making various function inside a class which are linked to each other to make the processor
easier
Todays code
#include <iostream>
using namespace std;
int main() {
int inputData, inputValue;
cout << "type 2 numers: \n";
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------
Week –2(1)
-Variables and assignment
-Data type and expressions
-Simple flow of control :the way in which conditions are followed example Elif
-Program style : it is for collaboration with the other programmers
perator
Initializing variable
We need to clear all the warning so that there is no problem in the long run.
\t
\\
\n
Setf(ios::fixed)
Cout.setf(ios::showpoint)
Cout.presicion(n)
After C++11 they defined a fixed size for a datatype
Auto – deduce the type acc to the value assigned
Reading character
Type string
Getline(cin,a); to avoid problems with strings
Bool – 1 true 0 is false
Athematic operators
Precedence mess higher priority to operators
Flow of control – way of giving instructions
Boolean expression
Todays code -
#include <iostream>
#include <string>
using namespace std;
int main() {
double rate, hours, grossPay;
cout << "Enter the rate and total hours respectively: " << endl;
cin >> rate >> hours;
if (hours > 40) {
grossPay = rate * 40 + (hours - 40) * rate * 1.5;
cout << "the total pay is " << grossPay << endl;
} else {
grossPay = rate * hours;
cout << "the total pay is " << grossPay << endl;
}
return 0;
}
Code 2
#include <iostream>
#include <string>
using namespace std;
int main() {
int x;
cout << "enter a value for x " << endl;
cin >> x;
if (x <= 100 && x >= 90) {
cout << "A" << endl;
} else if (x <= 89 && x >= 80) {
cout << "B" << endl;
} else if (x <= 79 && x >= 70) {
cout << "C" << endl;
} else if (x <= 69 && x >= 60) {
cout << "D" << endl;
} else {
cout << "F" << endl;
}
return 0;
Week 3 (1)
Ø If-else Flow control
Ø AND &&
Ø OR ||
Ø NOT !
Ø Be careful with inequalities.
Ø Pitfall: use of = and ==.
Ø Compound Statement.
Ø #include <iostream>
#include <string>
using namespace std;
int main(){
string name;
cout << "Enter patient name: "<< endl;
cin>> name;
int age;
cout << "Enter patient age: "<< endl;
cin>> age;
string blevel;
cout << "Does the patient have high blood level "<< endl;
cin>> blevel;
if ((age >= 55) && (blevel == "yes")){
cout << "Medical alert: "<< name << " sees a doctor."<< endl;
}
else if ((age >= 55) && (blevel == "no")){
cout << name << ", you are in good health. See you next checkup."<< endl;
}
else if ((age < 55) && (blevel == "yes")){
cout << "Warning: " << name << ", seeing a doctor is recommended."<< endl;
}
return 0;
}
Ø Simple loops.
Ø While loop.
Ø While loop operation – Boolean.
Ø While loop syntax.
Ø Do-while loop.
Ø Do-while execute at least one time.
Ø Increment and decrement.
Ø #include <iostream>
using namespace std;
int main(){
int a=2;
cout<<a++<<endl;
cout<<a<<endl;
cout<<++a<<endl;
return 0;
}
Week 4
switch syntax
-top-daun design
algorithm
breaks program into small task and these small taks to smallr subtasks
RAND_MAX
Rand()
Alternative declaration
- order of argument
Week 5
Midterm and midterm discussion
Week 6
Week 7
Vectors
Container in a library
Vectors are defined by other programers and sometimes
we may need to do them by self
Can change its size and can provide bound checking
Its dynamic and can change according to the inputs
API – when we define a set of functions in a class by self
i.e. method
Example - check index which takes input as the index
number and
Declaring vectors
#include <vector>
Using namespace std;
Vector<char> vowels(5)
Vector<int> testScore(10)
Vector<char>vowels{‘a’,’e’,’I’,’o’,’u’};
The vector in the above line is the class
To access a vector the following syntax are used
Vector_name[index]
Vector_name.at(index)
Vector_name.pop_back to remov the last element
Vector.at(i)
Vector<int> a(4,0)
a.resize(x,y)
x-size
y-defaut value
begin and end
pointer is a variable that holds the memory address of
another variable of same type
int v =101;
int *p=&v
pointer refrences to the position of the variable
#include <iostream>
using namespace std;
int main() {
int a = 2, b = 3;
cout << a << b;
int *a1, *b1;
a1 = &a;
b1 = &b;
cout << &a1 << " " << &b1;
a = 20;
b = 30;
cout << a << " " << b;
cout << &a;
cout << &b;
cout << *a1 << " " << *b1;
cout << &a1 << " " << &b1;
return 0;
}
Week 8
Refrence parameters
Make changes to a variable after the
function ends
Indirectional operaters changes the value
the parameter points to
&x=adress
*x=value
#include <iostream>
using namespace std;
void swao(int* a,int* b){
int temp = *a;
*a=*b;
*b=temp;
}
int main() {
int x=5;
int *p=&x;
cout<<*p<<endl;
cout<<p<<endl;
cout<<x<<endl;
int *ptr=p;
cout<<*ptr<<endl;
cout<<ptr<<endl;
}
Id arrays and pointers
Int A[t] is assigned and address of A[0]
address of A + x * bytes to represent int
A + x is equivalent to &(A[x])
*(A + x) is equivalent to A[x]
Array is the address in sequence
Structures and classes have a difference which I need to figure out, major factors could be
inheritance
Structure have all the variable and elements public and a class is private