C++ My notes(2)
- sondip poul singh
- Feb 1, 2019
- 2 min read
Use of Pointer:
A program to find the average of an array by pointer:
struct person{ string name; int age; };
int average_function(int *p,int size); int main() { int numbers[5]; int len; len=sizeof(numbers)/sizeof(numbers[0]); cout<<average_function(&numbers,len); return 0; }
double average_function(int *p,int size){ int sum=0; double avg; for(int i=0;i<size;i++) { sum=sum+p[i]; } avg=sum/size; }
#A program to find the bigger date by python
from datetime import datetime as dt mybirthday=dt.strptime("18/11/1994","%d/%m/%Y")
#Capital Y means a year of 4 digit...small y menas 2 digit year like 94 only #print("ok "+ str(mybirthday)) present_date=dt.strptime("1/2/2019","%d/%m/%Y")
if(mybirthday>present_date): print('mybirthday is bigger') else: print('present_date is bigger')
#A program to find the bigger time by python
from datetime import datetime as dt from datetime import timedelta as td import datetime mybirthday=dt.strptime("10/10/20","%I/%M/%S") #here I means 12 hour format for 24 hour format use H #print("ok "+ str(mybirthday)) present_date=dt.strptime("11/50/30","%I/%M/%S") sec=td.total_seconds(present_date-mybirthday) print(str(datetime.timedelta(seconds=sec)))
Enum:(Enumeration bengali meaning বিশেষ বিবরণ):
https://www.youtube.com/watch?v=x55jfOd5PEE
https://www.programiz.com/cpp-programming/enumeration
Enum is just a user defined data type.We can write
Enum season{
summer,winter,Rainy
}
those integral constants in season have values starting from zero like summer=0,winter=1 etc. and grown every time by adding 1 .We can give our own values like summer =10 rainy=30 etc. If we write summer=1 the other values will be 2,3....
now in main we can write
season x; //season type variable
x=winter;
if(x==1):
do something
there is another way of declaring the enum variable(object):
Enum season{
summer,winter,Rainy
}x;
Actually enum is useful when we set values of our variables and want to use them in some sort of class. Instead of writing the variable and their values separately its better to inclose them in a type and use their names when we need the specific values.At the end of the day enum type data constants are just integer numbers.
3d array:
int test[2][3][4] = { { {3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23, 2} }, { {13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4, 9} } };
(two row,3 column and every colum there are 4 elements)
https://www.programiz.com/cpp-programming/examples/matrix-multiplication
traspose a matrix:
https://www.programiz.com/cpp-programming/examples/matrix-transpose
Comments