0% found this document useful (0 votes)
2 views

class notes

The document provides an overview of computer components, programming concepts, and C++ syntax, covering topics such as CPU, RAM, data structures, algorithms, and object-oriented programming. It includes examples of code snippets demonstrating variable assignment, flow control, and the use of functions and vectors. Additionally, it discusses programming styles, memory access, and the differences between structures and classes.

Uploaded by

hmslea1215
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

class notes

The document provides an overview of computer components, programming concepts, and C++ syntax, covering topics such as CPU, RAM, data structures, algorithms, and object-oriented programming. It includes examples of code snippets demonstrating variable assignment, flow control, and the use of functions and vectors. Additionally, it discusses programming styles, memory access, and the differences between structures and classes.

Uploaded by

hmslea1215
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Chapter 1

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

First comp.-von Neumann architecture


Memory
Large data items may be for 1 byte like numbers
Data or code
Storage media
Hard disk
Floppy
Compact
Optical-magnetic-\
Memory access
RAM
Sequential access-when searching through other items
Processor
Execute program
-athematic operations
But for IC circuits can only add
Comp. software
Higher-level language
Only for humans to understand like python, c++
Lower level language is for the computer
Compilers
Higher level to machine level
LINKERS
LINKS THE CODE TO a library eg(#include<header_file>
Algorithms
Set of instructions to obtain a particular result
Program design
Data structure and a process to write a organised code
Implementations phase

Object oriented programing


Class – blueprint category

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

USING NAMESPACE STD – to avoid name conflict


We use std:: to use different type of namespaces
Variable declaration rules
Namespaces define variables such as cin,cout and with the namespace the usage of these variable changes eg std,
adt.
In high level language we cannot directly change the code but in lower we can
\n to get to next line
Endl to go to last line
If we put double value in a interger value then we just get the number before the decimal

Todays code
#include <iostream>
using namespace std;

int main() {
int inputData, inputValue;
cout << "type 2 numers: \n";

cin >> inputData >> inputValue;


cout << "inputdata : " << inputData << " inputvalue : " << inputValue << endl;
cout << "my name is harsh";

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

THERE are many types of programming styles

Variables and assignment


Numbers, underscore and letters
1st one cannot be a number and give meaningful names.
C++, Linux is case sensitive.
No spaces; camelCase or underline but not mixed.
Identifier is a variable, but variable is not a identifier ex- int and main are identifiers.
Keywords are words used the C++ language so cannot be used as variable
Cin and Cout are not keywords but variable that are dependent on the namespace.
DATA STRUCTURE
While true break
-----------------
Return- gives a result of the function after calculations.
Continue- if satisfied then the code following it is not followed
SizeOf- tells the size of data type, we need to know size to prevent overflow.
Const – for value u don't want to modify later
Let- value u want to modify.
“=” is a assignment operator
“==” is a equal o

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

-predefined functions in c++

Some return a value and some are void\

-Functions call syntax

Abs(x) is for int

Fabs(x) is for double value

Random number generator

RAND_MAX
Rand()

Alternative declaration

-List formal parameter names

-list types but not names

- order of argument

Compiler checks the argument but not the order

Overloading function names

More than 1 defination for same function

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

Int *x is 4 bits and double is also 4 bits and double


Pointer to pointer –
int x=5
Int *p=&x
Int *prt =*p
Prt prints address and *prt prints 5
Todays codes

#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

Void printelementOfarray(int* ptr,int size){


For(int I =0;i<size;i++){
Cout<<*(prt+i)<<endl;
}

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

Midterm term = structure and classes included


Structures-------
Oop (object oriented programing )
Encapsulation helps in information hiding
Class(it’s a blueprint/category) has method; in the following
example wd and rg
We need to use keyword public to access the variable from the class
as they are private
Class Student{
Public;
String student;
Int studentId;
Char gender
Void Wd(string);
Void rg(string course name);
}
Class’s variable are called classes , sequential allocation of memories included
Class is a data type
For structures the attribiutes are public.
2 dif struct can have same name.
Struct time {
Int hour;
Int min;
};
Structure don’t have functions.
Class and structures end with a “;”

Accessing members of structures


Dot operator(.)for structure and objects
Arrow operator(->)

You might also like