Forwarded from Mohammed Nebil @Conso
π3
Forwarded from Algo programmers
GENERICS IN C++
ππ½Generics is the idea to allow type (Integer, String, β¦ etc and user-defined types) to be a parameter to methods, classes and interfaces. For example, classes like an array, map, etc, which can be used using generics very efficiently.
β Generics can be implemented in C++ using Templates. Template is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we donβt need to write the same code for different data types.
For example let's look the program that sort() using the idea of generics:_
ππ½Generics is the idea to allow type (Integer, String, β¦ etc and user-defined types) to be a parameter to methods, classes and interfaces. For example, classes like an array, map, etc, which can be used using generics very efficiently.
β Generics can be implemented in C++ using Templates. Template is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we donβt need to write the same code for different data types.
For example let's look the program that sort() using the idea of generics:_
#include <iostream>
using namespace std;
// One function works for all data types.
// This would work even for user defined types
// if operator '>' is overloaded
template <typename T>
T myMax(T x, T y)
{
return (x > y) ? x : y;
}
int main()
{
// Call myMax for int cout << myMax<int>(3, 7) << endl;
// call myMax for double cout << myMax<double>(3.0, 7.0) << endl;
// call myMax for char cout << myMax<char>('g', 'e') << endl;
return 0;
}π1
#include<iostream>
using namespace std; main() { int i = 1, j = 2, k = 3, r; r = (i, j, k); cout<<r<<endl; //the output is:
using namespace std; main() { int i = 1, j = 2, k = 3, r; r = (i, j, k); cout<<r<<endl; //the output is:
Anonymous Poll
24%
1
27%
3
13%
2
58%
compiler error
Anonymous Poll
12%
10
37%
20
39%
11
17%
21
π1
Anonymous Poll
16%
1
45%
2
28%
compiler error
16%
runtime error
π1
Error handling during file operations in C/C++
β It is quite common that errors may occur while reading data from a file in C++ or writing data to a file.
Below are some Error handling functions during file operations in C/C++:
Β»sample code: https://t.me/learntocodecpp/454
Β»sample code: https://t.me/learntocodecpp/457
The function
Β»sample : https://t.me/learntocodecpp/458
β It is quite common that errors may occur while reading data from a file in C++ or writing data to a file.
Below are some Error handling functions during file operations in C/C++:
ferror():
β€οΈThe ferror() function checks for any error in the stream. It returns a value zero if no error has occurred and a non-zero value if there is an error. Β»sample code: https://t.me/learntocodecpp/454
clearerr():
π€The function clearerr() is used to clear the end-of-file and error indicators for the stream.Β»sample code: https://t.me/learntocodecpp/457
The function
perror()
π€stands for print error. In case of an error, the programmer can determine the type of error that has occurred using the perror() function.Β»sample : https://t.me/learntocodecpp/458
Travel agency managnment system by using oop PROJECT.cpp
15.7 KB
project one:<source AAU>
Q1.......is the standard markup language for creating webpages
Anonymous Quiz
12%
Python
7%
C++
78%
Html
4%
C#
the end tag for the HTML element <br> is:
Anonymous Quiz
52%
</br>
11%
</p>
21%
<br> itself
16%
none
Java how to program late objects in... (z-lib.org).pdf
8.4 MB
Object oriented programming>OOPπππΏ
π3