EvoNext
1.79K subscribers
272 photos
16 videos
266 files
484 links
Download Telegram
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:_

#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
Class is declared using the class keyword, and structure is declared using the struct keyword. //C++
πŸ‘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:
Anonymous Poll
24%
1
27%
3
13%
2
58%
compiler error
#include<iostream>

using namespace std; main() { int a[] = {10, 20, 30}; cout<<*a+1; }
Anonymous Poll
12%
10
37%
20
39%
11
17%
21
πŸ‘1
#include<iostream>

using namespace std; main() { int a[] = {1, 2}, *p = a; cout<<p[1]; }
Anonymous Poll
16%
1
45%
2
28%
compiler error
16%
runtime error
πŸ‘1
Chapter 8 .pdf
2.1 MB
πŸ‘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++:
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
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
HTML5NotesForProfessionals.pdf
1.3 MB
More on #HTML πŸ‘ŒπŸ‘πŸ‘πŸΏ
πŸ‘3
Java how to program late objects in... (z-lib.org).pdf
8.4 MB
Object oriented programming>OOPπŸ‘ŒπŸ‘πŸΏ
πŸ‘3