What are C plus plus intrinsic functions?
Most functions are available from libraries, however some functions are built-in to the compiler itself. A built-in function is therefore an intrinsic function.
Some intrinsics are only available as built-in functions while others also have standard function equivalents. You can choose to use some or all intrinsics either by using the #pragma compiler directive or via a compiler optimisation switch, such as /Oi in MSVC++, or indeed both.
Intrinsic functions are typically inline expanded to eliminate the overhead of a function call, and some will also provide information back to the compiler in order to better optimise the emitted code.
Intrinsics affect the portability of code but are generally more portable than inline assembler. Indeed, some architectures do not support inline assembler, thus intrinsics are nothing if not essential where optimal code is a requirement.
Your compiler's documentation should provide a complete list of the intrinsic functions available for each platform it supports, along with the standard function equivalents.
What are the differences between assembly and high-level language c plus plus?
Assembly language is a procedural language with a low-level of abstraction between the source code and the resulting binary code. Assembly language is entirely machine specific, and the onus is therefore upon the programmer to code specifically for that machine. The code cannot be transferred and assembled on a different architecture -- it must be re-written in its entirety.
High-level languages such as C++ have a high level of abstraction between the source code and the resulting binary code, with a high degree of separation between the source and the machine. This abstraction renders the source code far more portable than low-level languages as the onus is now upon the compiler to produce the machine specific code, not the programmer. C++ utilises a combination of structured and object-oriented programming to achieve this abstraction, allowing the programmer to create highly robust code that is not only easier to read, but easier to maintain, regardless of its complexity.
How is memory allocated for structres in C plus plus?
Memory is allocated to struct types exactly the same way as memory is allocated to class types. Memory is allocated to each member variable in the same order as they are declared, according to the size of each member plus any padding required for alignment purposes (which is typically the word size of the architecture).
The least-derived base class is always allocated first and, where multiple-inheritance is employed, the order of inheritance in the derived class declaration determines the order of allocation for its base classes. However, the order of the base classes has no effect upon the combined size of those base classes, only upon the order in which they are allocated.
Note that in order to minimise wasted memory in each individual class, it is generally best to declare class member variables in descending order of size. Consider the following, where base1 and base2 have the exact same member types but in different orders, such that base2 occupies less memory than base1.
derived has no members save those it inherits from base1 and base2, thus its total size is the sum of its base classes.
#include<iostream>
struct base1
{
char a;
int b;
char c;
char d;
};
struct base2
{
int e;
char f;
char g;
char h;
};
struct derived: public base1, public base2 {};
int main()
{
std::cout<<"base1 is "<<sizeof(base1)<<" bytes"<<std::endl;
std::cout<<"base2 is "<<sizeof(base2)<<" bytes"<<std::endl;
std::cout<<"derived is "<<sizeof(derived)<<" bytes"<<std::endl;
}
base1 is 12 bytes
base2 is 8 bytes
derived is 20 bytes
Write a c plus plus program for finding the inverse of a given matrix?
#include<stdio.h>
#include<math.h>
float detrm(float[][],float);
void cofact(float[][],float);
void trans(float[][],float[][],float);
main()
{
float a[25][25],k,d;
int i,j;
printf("ENTER THE ORDER OF THE MATRIX:\n");
scanf("%f",&k);
printf("ENTER THE ELEMENTS OF THE MATRIX:\n");
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
scanf("%f",&a[i][j]);
}
}
d=detrm(a,k);
printf("THE DETERMINANT IS=%f",d);
if(d==0)
printf("\nMATRIX IS NOT INVERSIBLE\n");
else
cofact(a,k);
}
/******************FUNCTION TO FIND THE DETERMINANT OF THE MATRIX************************/
float detrm(float a[25][25],float k)
{
float s=1,det=0,b[25][25];
int i,j,m,n,c;
if(k==1)
{
return(a[0][0]);
}
else
{
det=0;
for(c=0;c<k;c++)
{
m=0;
n=0;
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
b[i][j]=0;
if(i!=0&&j!=c)
{
b[m][n]=a[i][j];
if(n<(k-2))
n++;
else
{
n=0;
m++;
}
}
}
}
det=det+s*(a[0][c]*detrm(b,k-1));
s=-1*s;
}
}
return(det);
}
/*******************FUNCTION TO FIND COFACTOR*********************************/
void cofact(float num[25][25],float f)
{
float b[25][25],fac[25][25];
int p,q,m,n,i,j;
for(q=0;q<f;q++)
{
for(p=0;p<f;p++)
{
m=0;
n=0;
for(i=0;i<f;i++)
{
for(j=0;j<f;j++)
{
b[i][j]=0;
if(i!=q&&j!=p)
{
b[m][n]=num[i][j];
if(n<(f-2))
n++;
else
{
n=0;
m++;
}
}
}
}
fac[q][p]=pow(-1,q+p)*detrm(b,f-1);
}
}
trans(num,fac,f);
}
/*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/
void trans(float num[25][25],float fac[25][25],float r)
{
int i,j;
float b[25][25],inv[25][25],d;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
b[i][j]=fac[j][i];
}
}
d=detrm(num,r);
inv[i][j]=0;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
inv[i][j]=b[i][j]/d;
}
}
printf("\nTHE INVERSE OF THE MATRIX:\n");
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
printf("\t%f",inv[i][j]);
}
printf("\n");
}
}
Input and output statements in C?
For input: scanf("%d",&the value u wanna get into pgm); For output: printf("%d",the value u wanna give to out); Note: u ve to be sure in the letter u put after %.because it ll change depends on variable.eg:int,char,floatdouble,string,decimal,hex,oct..etc Rgds, BM
Objects are constructed. You can't make a new object without invoking a constructor. In fact, you can't make a new object without invoking not just the constructor of the object's actual class type, but also the constructor of each of its superclasses including the Object class itself! Constructors are the code that runs whenever you use the keyword new.
What is Microsoft visual c plus plus 2005 redistributable?
A redistributable file(not just an MS VC++ 2005 redistributable) is a file that the software vendor allows you to redistribute along with derivative works that you provide using their software. Most redistributables are DLL's, which are shared libraries. The software product depends on these libraries, and derivative work that you write, such as programs using that compiler, also depend on these libraries. In terms of C++, examples are the run-time library and the class libraries for Microsoft Foundation Classes. The file is "redistributable" because the license you have permits you to bundle that file with your product, usually contained within an installer package. You need to very carefully read the license agreement, and make sure you know exactly what is considered "redistributable", and what is not. An example of a non-redistributable file would be a debug version of the run-time library. Usually, Microsoft redistributables are contained in a REDIST directory created when you install the product but, again, read the license agreement.
How do you overload function call and Array sub-scripting operators?
Overloading the "function call" operator, i.e. operator()(), can be achieved by defining a method with the following form:
For example, here's how it would look in the simplest case (no argument or return value):
class Callable {// ...public:voidoperator()() {// do something interesting}// ...};
Overloading the array subscript operator, i.e. operator[](), is just as easy. This operator always takes a single argument (the subscript). Here's a template for a method which overloads this operator:
For example:
class Subscriptable {// ...public:doubleoperator[](unsigned index) {// compute and return a double}// ...};
Code for palindrome checking in C programming?
bool is_palindrome (char* str) {
if (str==0) return false;
int len = strlen (str);
if (len==0) return false;
int len2 = 0;
char* str2 = malloc (len + 1);
char* begin;
char* end;
char c;
for (int i=0; i<len; ++i) {
c = tolower (str[i]);
if ((c>='a' c<='z') (c>='0' c<='9')) str2[len2++] = c;
}
begin = str2;
end = begin+len2-1;
while ((*begin==*end) && (begin<end)) { ++begin; --end; }
free str2;
result = end<=begin;
}
What is a function prototype in C and C plus plus?
A function prototype is basically a definition for a function. It is structured in the same way that a normal function is structured, except instead of containing code, the prototype ends in a semicolon.
Normally, the C compiler will make a single pass over each file you compile. If it encounters a call to a function that it has not yet been defined, the compiler has no idea what to do and throws an error. This can be solved in one of two ways.
The first is to restructure your program so that all functions appear only before they are called in another function.
The second solution is to write a function prototype at the beginning of the file. This will ensure that the C compiler reads and processes the function definition before there's a chance that the function will be called.
For example, let's take a look at a few functions form a linked list implementation.
// Sample structures
struct linked_list_node {
int data;
struct linked_list_node *next;
};
struct linked_list {
int size;
struct linked_list_node *root;
};
// Function Prototypes
void deleteLinkedList(struct linked_list *list);
void deleteNodes(struct linked_list_node *node);
// Actual functions:
// deletes the given linked list
void deleteLinkedList(struct linked_list *list) {
if( list != NULL ) {
// delete nodes
deleteNodes(list->root);
// lose the pointer
list->root = NULL;
// delete actual list
free(list);
}
}
// deletes all nodes starting at node
void deleteNodes(struct linked_list_node *node) {
if( node != NULL ) {
// deallocate next, if it exists
if( node->next != NULL ) {
deleteNodes(node->next);
// lose the pointer
node->next = NULL;
}
// deallocate node
free(node);
}
}
What is the concept of flag in c plus plus?
we will give sujika then output will be ok
here first give su ofter jika then print ok
b/w su nd jika there no letters give answer plz
What is the datatype of a class?
While there are obvious data types like primitives (boolean, char, byte, short, int, long, float, double) and arrays, really any class which stores some form of information can be considered a data type. Objects like String, BigInteger, and the whole Collections framework also belong in this category.
C programming code for newton raphson method to solve quadratic equation?
yes
This is the codes for Newton-Raphson method for solving Quadratic equations
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(x)(x*x*x)-(4*x)
#define FD(x)(3*x*x)-4
#define MAXIT 20
void main()
{
int count;
float x0,x1,fx,fdx;
clrscr();
printf("NEWTON-RAPHSON METHOD\n");
printf("---------------------\n");
printf("initial value:");
scanf("%f",&x0);
count=1;
begin:
fx=F(x0);
fdx=FD(x0);
x1=(x0-(fx/fdx));
if(fabs((x1-x0)/x1)<0.00001)
{
printf("The root is:%f\n",x1);
printf("Iteration is:%d\n",count);
}
else
{
x0=x1;
count=count+1;
if((count<MAXIT));
goto begin;
}
getch();
}
What is mean by redirection in c plus plus?
Redirection applies to the standard input/output devices. Although it is up to the user to decide which device provides input and which provides output for your program, the programmer can choose to redirect those devices as they see fit. However, it is important that the programmer restore the original devices as soon as they have finished with them.
The following example demonstrates one way of redirecting the standard input/output devices programmatically:
#include <iostream>
#include <fstream>
#include <string>
void f()
{
std::string line;
while (std::getline(std::cin, line)) // input from stdin
{
std::cout << line << "\n"; //output to stdout
}
}
int main()
{
std::ifstream in("in.txt");
std::streambuf *cinbuf = std::cin.rdbuf(); // save old buf
std::cin.rdbuf(in.rdbuf()); // redirect std::cin to in.txt!
std::ofstream out("out.txt");
std::streambuf *coutbuf = std::cout.rdbuf(); // save old buf std::cout.rdbuf(out.rdbuf()); // redirect std::cout to out.txt!
std::string word;
std::cin >> word; // input from the file in.txt
std::cout << word << " "; // output to the file out.txt
f(); // call function
std::cin.rdbuf(cinbuf); // reset to standard input again
std::cout.rdbuf(coutbuf); // reset to standard output again
std::cin >> word; // input from the standard input
std::cout << word; // output to the standard input
}
Why is it a good practice to initialize pointers?
A pointer is initialized by assigning the address of some object to it ...
int a; // an integer
int *pa; // a pointer
pa = &a; // initialize the pointer
(*pa); // use the pointer
... by allocating memoryand assigning that address to it ...
int *pa; // a pointer to an integer
pa = malloc (1 * sizeof(int)); // allocate
if (pa == NULL) {... exception processing ...}
(*pa); // use the pointer
... or by doing address computation with it ...
int a[10]; // an array of integers
int *pa; // a pointer to an integer
pa = &(a+3); // initialize to the fourth element
(*pa); // use the fourth element
What is syntex error in c plus plus?
A string is a sequence of character data types typically stored in a vector or an array. The two main string classes are std::string and std::wstring, both of which can be found in the <string> header file. std::string is a specialisation of std::vector<char> while std::wstring specialises std::vector<wchar_t>. The latter is often known as wide-string, ideally suited to UTF-16 encoding. The former can be used for both ASCII and UTF-8 encoding. These are generally all you need.
You can construct objects of the string classes as follows:
std::string str ("Hello world!"); // C++ string
std::wstring wstr (L"Hello world!"); // C++ wide-string
You can also make use of C-style strings, however it's best to limit their use to fixed-length strings. These can be declared as follows:
char cstr[] = "Hello world!";
wchar_t cwstr[] = L"Hello world!";
You can use variable length C-strings if you wish but you're simply creating unnecessary work for yourself. The only real advantage is that you save some memory (4-bytes per string on a 32-bit system) but restrict yourself to the C standard library functions, most of which are inefficient compared to the equivalent C++ string member methods (primarily because the size of a C++ string does not need to be continually recalculated -- it is a given). C++ strings are also easily converted to and from C-style strings and they manage their own resources for you, which ultimately makes them much easier to use.
Although not physically part of the Standard Template Library, C++ strings adhere to STL semantics, including bidirectional, random-access iteration through the character sequence as well as subscript notation to access individual characters. STL algorithms and functions can also be applied, although the member functions are sufficient for most of the operations you will need to perform upon strings, such as appending strings and searching within strings.
Note that insertion of one string within another is not supported. This is because vectors are specifically designed to add new elements to the end of the sequence rather than the middle or beginning of the sequence. To insert one string inside another, it is more efficient to create a new string, reserving the number of characters required for both the original string plus the inserted sub-string, and simply appending the sub-strings accordingly. The new string can then be assigned to the original string if required.
By reserving characters, the new string doesn't have to be resized with each append operation. Resizing only occurs when an append operation exceeds the current allocation and may result in a reallocation if the current memory block has no room to expand. Reallocations are expensive as the original string must be copied to the new allocation, which means you need more than double the memory of the original allocation (at least for the duration of the copy operation), not to mention the performance impact of physically copying the string. The fewer reallocations you make the better, so plan ahead. Calculate and reserve what you need in advance.
C++11 also introduces move semantics which helps eliminate a lot of the copying operations that would otherwise occur when passing string values to or from functions (thus creating temporary strings). For instance, when you assign a function that returns a string to another string, two complete copies of the string are made. The first is made by the function itself, copying its local string to the function's return value (thus creating a temporary). The second is made when that return value is subsequently assigned to your string (if you don't assign, the temporary simply falls from scope, but still results in an unnecessary copy being made). With move semantics, no copies are made, the temporary simply takes ownership of the function's string and then passes that ownership onto your string.
This is made possible by the fact a string is nothing more than a pointer to a memory allocation plus the size of that allocation (in characters). By passing these two values alone, the new string immediately takes ownership of the allocation. The old string simply nullifies its pointer so when it falls from scope it doesn't destroy the allocation. As an implementation detail, all the actual work is done behind the scenes so the user is largely unaware of what's going on, the only visible sign being the much-improved performance. Move semantics apply to the entire STL in C++11 but can also be applied to your own classes. If you classes "own" resources, remember to provide move semantics so they can pass that ownership on automatically. Move semantics are achieved through a move constructor as well as a move assignment operator. It won't entirely eliminate the need to copy objects, but it will completely eliminate the need to make unnecessary copies.
Can c plus plus run on windows?
Windows 7 supports programs written in any language, including C and C++. However, the question is whether these programs support Windows 7 or not. If they were written for another platform entirely, such as the Apple Mac, then obviously they won't be supported.
Note that neither the C nor C++ languages, by themselves, support any particular operating systems, but they are generic enough to be able to create console applications that can run on most platforms without major modification. But in order to target a specific platform you need the appropriate headers and libraries for that platform. These are generally provided by your integrated development environment (IDE) of which there are many to choose from for each platform. In order to cater for multiple platforms code must be written specifically for each platform (using precompiler directives to filter out unwanted code) and must be compiled separately upon each supported platform.
C plus plus program of a palindrome?
There are several ways to determine if a string is a palindrome or not. Typically, you must first ignore all spacing, capitalisation and punctutation within the string, which can be done by copying the string, character by character, ignoring all non-alphanumeric characters. You then point to the first and last characters in the modified string and, so long as both characters under the pointers are the same, work the pointers towards the middle of the string until the pointers either meet in the middle or they pass each other. That is, if the string has an odd count of characters, the pointers will meet at the middle character, otherwise they will pass each other. At that point you can say with certainty the string is a palindrome. If the characters under the pointers differ at any time, then the string is not a palindrome. This is fairly straightforward to program.
A more interesting problem is when you have to locate the longest palindrome within a string which is not itself a palindrome. For instance, the string "Madam, I'm Adam is a palindrome" is not a palindrome, but it does contain one: "Madam I'm Adam". In this case we cannot point to the first and last characters and work towards the middle. Instead, we have to test every possible substring of the string. We do this by starting at the first character and treat it as if it were actually the middle character of a palindrome, and then move our pointers to the left and right of this character while the characters match. When they no longer match, or one of the pointers has reached either end of the string, we store the longest palindrome found up to that point and then move onto the next character and treat it as the middle character. If we continue in this manner, treating every character as if it were the middle character of a palindrome, we will eventually locate the longest palindrome.
The problem with this approach is when the longest palindrome has an even number of characters instead of an odd number. To get around this we simply place a single space between each character, and treat each of those as being the middle character as well. When a palindrome is found, we simply remove the spaces. In this way we can use exactly the same algorithm to cater for both odd and even character palindromes.
The only remaining problem is when we wish to print the palindrome itself. Since this will be a substring of the original string, we cannot use the modified string we used to locate the palindrome. One way to get around that is to store the original positions of each letter in an array of indices, and use that array to determine where the substring lies with in the original string.
The following program demonstrates this technique in full. The key function is the ispalindrome() function, which accepts a lower-case copy of the string (including the original spacing an punctuation), and a vector that contains the indices of each letter within the string (ignoring puctuation and spacing), separated by -1 values (representing the implied spaces between each letter). The pos value tells the function which index of the vector is to be treated as the middle character of the potential palindrome, while x and y are output parameters that determine the start and end of the palindrome within the vector. The function returns true if a palindrome was found, and the x and y values can be used to extract the palindrome from the original string, using the indices stored in the vector. Note that when the search for a palindrome fails, we step back the x and y indices by one, and if the vector index is -1, then we step back another index. We then test the x and y values to see if they indicate a palindrome was found or not.
The strip() function is another key function. This generates the vector from the lower case copy of the original string. Although we could eliminate the -1 values at the start and end of the vector, it's simpler to just leave them in.
You will note that the program can cater for strings that are themselves palindromes, as well as strings that contain palindromes.
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string input_string(string prompt)
{
cout<<prompt<<":\t";
string input;
getline(cin, input, '\n');
return(input);
}
void convert_tolower(string& s)
{
for(string::iterator i=s.begin(); i!=s.end(); ++i)
*i=tolower(*i);
}
vector<int> strip(const string& s)
{
vector<int> v;
v.push_back(-1);
for(int i=0; i<s.size(); ++i)
{
if((s[i]>='a' && s[i]<='z') (s[i]>='0' && s[i]<='9'))
{
v.push_back(i);
v.push_back(-1);
}
}
return(v);
}
bool ispalindrome(const string s, const vector<int> v, int pos, int& x, int& y)
{
for(x=pos,y=pos; x>=0 && y<v.size(); --x, ++y)
if( v[x]!=-1 && ( s[v[x]]!=s[v[y]] ))
break;
++x, --y;
if( v[x]==-1 )
++x, --y;
return(x>=0 && x<y && y-x>1);
}
int main()
{
string input;
while(1)
{
input=input_string("Enter a string");
if(input.size()==0)
break;
string copy(input);
convert_tolower(copy);
vector<int> v=strip(copy);
string pal;
int pos=0;
for(int i=0; i<v.size(); ++i)
{
int start=0, end=0;
if( ispalindrome( copy, v, i, start, end))
{
string tmp( input.substr(v[start],v[end]-v[start]+1));
if( tmp.size() > pal.size() )
{
pal = tmp;
pos = v[start];
}
}
}
if( pal.size() )
{
cout<<"Palindrome:\t";
for(int i=0; i<pos; ++i)
cout<<" ";
cout<<pal<<"\n"<<endl;
}
else
cout<<"The string contains no palindromes!\n"<<endl;
}
return(0);
}
Example output:
Enter a string: Madam, I'm Adam
Palindrome: Madam, I'm Adam
Enter a string: Madam, I'm Adam is a palindrome
Palindrome: Madam, I'm Adam
Enter a string: In girum imus nocte et consumimur igni
Palindrome: In girum imus nocte et consumimur igni
Enter a string: 0123456765432
Palindrome: 23456765432
Enter a string:
Press any key to continue . . .
How can a node be inserted in the middle of a linked list?
when you have two nodes and when you want to insert the third node between the 1 & 2 then, store the address of the third in the next pointer of 1st and address of 2nd in the next pointer of 3rd.
by kochu
What is the importance of functions in c plus plus?
Without functions, a non-trivial program would contain repeated code segments and would be extremely difficult to maintain. Even if you don't write any functions of your own, you still have to call the built-in functions to actually do anything worthwhile.
User-defined functions allow you to structure your source code more efficiently. If you find yourself writing the same code segment over and over, then it makes sense to turn it into a function. Apart from anything else, it reduces the chance of making a mistake or a typo. And with only one copy of the code it becomes that much easier to adjust the function to improve its efficiency or add additional functionality. Moreover, you can break large and complex problems down into smaller functions, each of which can be broken down further if required. This is known as re-factoring. The end result is your code becomes much easier to read and is therefore much easier to maintain.
Every function you write should do a small amount of work, and should do it extremely well and as efficiently as possible. A one-line comment is usually more than sufficient to describe the purpose of a function. But if your function is large and complex, and heavily commented, re-factoring should be considered -- especially if you find it difficult to follow yourself.
While there is a performance penalty in making a function call, your compiler should be intelligent enough to work out which functions can be inline expanded (just as if you'd duplicated the code yourself). In general, only trivial and heavily repeated functions will be inline expanded, and only if the compiler believes there to be an advantage in doing so. While you can tell it which functions to inline expand, the compiler is usually free to ignore the request if it sees no advantage in doing so. Additional optimisers will check the resulting machine code more closely and make finer adjustments as they see fit. The end result should be reasonably efficient code, the only real compromise being overall code size vs. overall code speed (large code is not necessarily fast code).
What is the function of dos.h?
You can find a copy of that file in here:
http://ftp.ibiblio.org/pub/micro/PC-stuff/freedos/files/devel/c/dos.h
in case the server is down check the extracted file:
#ifndef __DOS_H
#define __DOS_H
#include <_defs.h>
#include <stddef.h>
#ifdef __WATCOMC__
#pragma pack( __push, 1 )
#endif
struct _R16BIT {
unsigned short ax, bx, cx, dx, si, di, es, cs, ss, ds, flags;
unsigned char cflag;
};
struct _R8BIT {
unsigned char al, ah, bl, bh, cl, ch, dl, dh;
};
union _INTR {
struct _R16BIT x;
struct _R8BIT h;
};
#define INTR _INTR
struct country {
int co_date; /* date format */
char co_curr[ 5 ]; /* currency symbol */
char co_thsep[ 2 ]; /* thousands separator */
char co_desep[ 2 ]; /* decimal separator */
char co_dtsep[ 2 ]; /* date separator */
char co_tmsep[ 2 ]; /* time separator */
char co_currstyle; /* currency style */
char co_digits; /* significant digits in currency */
char co_time; /* time format */
long co_case; /* case map */
char co_dasep[ 2 ]; /* data separator */
char co_fill[ 10 ]; /* filler */
};
#define COUNTRY country
struct DOSERROR {
int de_exterror; /* extended error */
char de_class; /* error class */
char de_action; /* action */
char de_locus; /* error locus */
};
struct date {
unsigned int da_year; /* current year */
unsigned char da_day; /* day of the month */
unsigned char da_mon; /* month (1 = Jan) */
};
struct dosdate_t {
unsigned char day; /* 1--31 */
unsigned char month; /* 1--12 */
unsigned int year; /* 1980--2099 */
unsigned char dayofweek; /* 0--6; 0 = Sunday */
};
struct devhdr {
long dh_next;
short dh_attr;
unsigned short dh_strat;
unsigned short dh_inter;
char dh_name[ 8 ];
};
struct dfree {
unsigned df_avail; /* Available clusters */
unsigned df_total; /* Total clusters */
unsigned df_bsec; /* Bytes per sector */
unsigned df_sclus; /* Sectors per cluster */
};
struct diskfree_t {
unsigned total_clusters;
unsigned avail_clusters;
unsigned sectors_per_cluster;
unsigned bytes_per_sector;
};
typedef struct {
char drive;
char pattern [ 13 ];
char reserved [ 7 ];
char attrib;
short time;
short date;
long size;
char nameZ [ 13 ];
} dosSearchInfo;
struct fatinfo {
char fi_sclus; /* sectors per cluster */
char fi_fatid; /* the FAT id byte */
int fi_nclus; /* number of clusters */
int fi_bysec; /* bytes per sector */
};
struct ffblk {
#ifdef __CLIB_LFN__
unsigned short cr_time; /* time of file creation */
unsigned short cr_date; /* date of file creation */
unsigned short ac_time; /* time of last file access */
unsigned short ac_date; /* date of last file access */
char ff_reserved[ 13 ]; /* reserved for use by DOS */
#else
char ff_reserved[ 21 ]; /* reserved for use by DOS */
#endif
char ff_attrib; /* attribute byte for file */
unsigned short ff_ftime; /* time of last write to file */
unsigned short ff_fdate; /* date of last write to file */
unsigned long ff_fsize; /* length of file in bytes */
#ifdef __CLIB_LFN__
char ff_name[ 256 ]; /* null-terminated filename */
unsigned short lfnhandle;/* DOS LFN support handle */
#else
char ff_name[ 13 ]; /* null-terminated filename */
#endif
};
struct find_t {
#ifdef __CLIB_LFN__
unsigned short cr_time; /* time of file creation */
unsigned short cr_date; /* date of file creation */
unsigned short ac_time; /* time of last file access */
unsigned short ac_date; /* date of last file access */
char reserved[ 13 ]; /* reserved for use by DOS */
#else
char reserved[ 21 ]; /* reserved for use by DOS */
#endif
char attrib; /* attribute byte for file */
unsigned short wr_time; /* time of last write to file */
unsigned short wr_date; /* date of last write to file */
unsigned long size; /* length of file in bytes */
#ifdef __CLIB_LFN__
char name[ 256 ]; /* null-terminated filename */
unsigned short lfnhandle;/* DOS LFN support handle */
#else
char name[ 13 ]; /* null-terminated filename */
#endif
};
#define _find_t find_t
struct fcb {
char fcb_drive;
char fcb_name[ 8 ],
fcb_ext[ 3 ];
short fcb_curblk,
fcb_recsize;
long fcb_filsize;
short fcb_date;
char fcb_resv[ 10 ],
fcb_currec;
long fcb_random;
};
struct xfcb {
char xfcb_flag;
char xfcb_resv[ 5 ];
char xfcb_attr;
struct fcb xfcb_fcb;
};
struct dostime_t {
unsigned char hour; /* Hours */
unsigned char minute; /* Minutes */
unsigned char second; /* Seconds */
unsigned char hsecond; /* Hundredths of seconds */
};
struct time {
unsigned char ti_min; /* minutes */
unsigned char ti_hour; /* hours */
unsigned char ti_hund; /* hundredths of seconds */
unsigned char ti_sec; /* seconds */
};
#ifdef __WATCOMC__
#pragma pack( __pop )
#endif
extern int __getversion( void );
extern char ** environ;
#define _version (*__getversion)()
extern unsigned char _osmajor;
extern unsigned char _osminor;
extern int absread( int drive, int sects, long lsect, void *buffer );
extern int abswrite( int drive, int sects, long lsect, void *buffer );
extern int allocmem( unsigned size, unsigned *seg );
extern int bdos( int ah, unsigned dx, unsigned al );
extern int bdosptr( int ah, void *argument, unsigned al );
extern int _callint( union INTR *regs );
extern struct COUNTRY *
country( int xcode, struct COUNTRY *ct );
extern void ctrlbrk( int ( *handler )( void ) );
extern void delay( unsigned mill );
extern void _disable( void );
extern unsigned _dos_allocmem( unsigned size, unsigned *seg );
extern unsigned _dos_close( int handle );
extern unsigned _dos_creat( const char *path, int attr, unsigned *handle );
extern unsigned _dos_creatnew( const char *path, int attr, unsigned *handle );
extern int __cdecl dosexterror( struct DOSERROR *errblk );
extern unsigned _dos_findfirst( char *filename, int attrib, void *strptr );
extern unsigned _dos_findnext( void *strptr );
extern unsigned _dos_findclose( void *strptr );
extern unsigned _dos_freemem( unsigned seg );
extern void __cdecl _dos_getdate( struct dosdate_t *ptr );
extern unsigned __cdecl
_dos_getdiskfree( unsigned char dr, struct diskfree_t *d );
extern unsigned _dos_getdrive( unsigned *disk );
extern unsigned _dos_getfileattr( const char *filename, unsigned *attrs );
extern unsigned __cdecl
_dos_getftime( int handle,
unsigned *date,
unsigned *time );
extern void __cdecl _dos_gettime( struct dostime_t *timeptr );
extern void ( interrupt far *
_dos_getvect( unsigned intno ) )( );
extern void _dos_keep( unsigned char retcode, unsigned size );
extern unsigned _dos_open( const char *path, unsigned flags, unsigned *handle );
extern unsigned _dos_read( int handle,
void far *buf,
unsigned len,
unsigned *nread );
extern unsigned _dos_setblock( unsigned newsize,
unsigned seg,
unsigned *max );
extern void _dos_setdate( struct dosdate_t *ptr );
extern void _dos_setdrive( unsigned disk, unsigned *total );
extern unsigned _dos_setfileattr( const char *filename, unsigned attrs );
extern unsigned _dos_setftime( int handle, unsigned date, unsigned time );
extern unsigned _dos_settime( struct dostime_t *timeptr );
extern void _dos_setvect( unsigned intno,
void ( interrupt far *vect )() );
extern time_t dostounix( struct date *date, struct time *time );
extern unsigned _dos_write( int handle,
void far *buf,
unsigned len,
unsigned *bytes );
extern void _enable( void );
extern int freemem( unsigned seg );
extern int getcbrk( void );
extern void __cdecl getdate( struct date *datep );
extern void __cdecl getdfree( unsigned char drive, struct dfree *dtable );
extern char * getdta( void );
extern void getfat( unsigned char drive, struct fatinfo *dtable );
extern void getfatd( struct fatinfo *dtable );
extern unsigned getpsp( void );
extern void __cdecl gettime( struct time *timeptr );
extern void ( interrupt far *
getvect( int intno ) )( );
extern int getverify( void );
extern int inp( unsigned id );
extern unsigned inpw( unsigned id );
extern unsigned inport( unsigned id );
extern unsigned char inportb( unsigned id );
extern void keep( unsigned char retcode, unsigned size );
extern void nosound( void );
extern int outp( unsigned id, int value );
extern unsigned outpw( unsigned id, unsigned value );
extern void outport( unsigned id, unsigned value );
extern void outportb( unsigned id, unsigned char value );
extern char * parsfnm( const char *cmdline, struct fcb *ptr, int al );
extern int peek( unsigned seg, unsigned offs );
extern char peekb( unsigned seg, unsigned offs );
extern void poke( unsigned seg, unsigned offs, int value );
extern void pokeb( unsigned seg, unsigned offs, char value );
extern int randbrd( struct fcb *buf, int rnum );
extern int randbwr( struct fcb *buf, int rnum );
extern int setblock( unsigned newsize, unsigned seg );
extern int setcbrk( int value );
extern void setdate( struct date *datep );
extern void setdta( char far *dta );
extern void setpsp( unsigned psp );
extern void settime( struct time *timeptr );
extern void setvect( int intno, void ( interrupt far *vect )() );
extern void setverify( int flag );
extern void sleep( unsigned x );
extern void sound( unsigned frequency );
extern void unixtodos( time_t longtime,
struct date *date,
struct time *time );
extern int unlink( const char *filename );
#define disable _disable
#define enable _enable
#define _A_NORMAL 0x00
#define _A_RDONLY 0x01
#define _A_HIDDEN 0x02
#define _A_SYSTEM 0x04
#define _A_VOLID 0x08
#define _A_SUBDIR 0x10
#define _A_ARCH 0x20
#define FA_NORMAL _A_NORMAL
#define FA_RDONLY _A_RDONLY
#define FA_HIDDEN _A_HIDDEN
#define FA_SYSTEM _A_SYSTEM
#define FA_LABEL _A_VOLID
#define FA_DIREC _A_SUBDIR
#define FA_ARCH _A_ARCH
#define NFDS 20
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define MK_FP( seg, ofs ) ( ( void * )\
( ( ( unsigned long )( seg ) << 16 ) |\
( unsigned )( ofs ) ) )
#define FP_SEG(fp) ( ( unsigned )( ( unsigned long )( fp ) >> 16 ) )
#define FP_OFF(fp) ( ( unsigned )( fp ) )
#define __peek( a,b ) ( *( ( int far * ) MK_FP ( ( a ), ( b ) ) ) )
#define __peekb( a,b ) ( *( ( char far * ) MK_FP ( ( a ), ( b ) ) ) )
#define __poke( a,b,c ) ( *( ( int far * ) MK_FP ( (a),(b)) ) = ( int )(c))
#define __pokeb( a,b,c ) ( *( ( char far * ) MK_FP ( (a),(b)) ) = ( char )(c))
#define peek( a,b ) ( *( ( int far * ) MK_FP ( ( a ), ( b ) ) ) )
#define peekb( a,b ) ( *( ( char far * ) MK_FP ( ( a ), ( b ) ) ) )
#define poke( a,b,c ) ( *( ( int far * ) MK_FP ( (a),(b)) ) = ( int )(c))
#define pokeb( a,b,c ) ( *( ( char far * ) MK_FP ( (a),(b)) ) = ( char )(c))
#ifndef __NO_INLINE_FUNCTIONS
#pragma aux _enable = "sti";
#pragma aux _disable = "cli";
#pragma aux inp = "in al, dx" parm [dx] value [al] modify [ax dx];
#pragma aux inpw = "in ax, dx" parm [dx] value [ax] modify [ax dx];
#pragma aux inport = "in ax, dx" parm [dx] value [ax] modify [ax dx];
#pragma aux inportb = "in al, dx" parm [dx] value [al] modify [ax dx];
#pragma aux outp = "out dx, al" parm [dx] [al] value [al] modify [ax dx];
#pragma aux outpw = "out dx, ax" parm [dx] [ax] value [ax] modify [ax dx];
#pragma aux outport = "out dx, ax" parm [dx] [ax] modify [ax dx];
#pragma aux outportb = "out dx, al" parm [dx] [al] modify [ax dx];
#endif
#endif
When do you use protected visibility specifier to a class member in C?
a class member declared as private can only be accessed by member functions and friends of that class
a class member declared as protected can only be accessed by member functions and friends of that class,and by member functions and friends of derived classes
What are the implecations of making a function pure virtual function?
Only class instance methods can be rendered as pure-virtual functions (or pure-virtual methods, to be precise). Non-member functions and static member methods cannot be declared pure-virtual.
The implication of declaring a pure-virtual function is that the class to which it is a member becomes an abstract data type (or abstract base class). This means you cannot instantiate an object of that class, you can only derive classes from it. Moreover, the derived classes must also implement the pure-virtual functions or they, too, become abstract data types. Only concrete classes that contain a complete implementation can be instantiated, although they can inherit implementations from their base classes (but not from the class that initially declared the method).
Pure-virtual functions ensure that you do not instantiate base class objects that are not intended to be instantiated (they are conceptual rather than actual objects) and that derived objects provide a specific implementation. Typically, all methods of an abstract base class will be declared pure-virtual to ensure correct behaviour in derived classes through a common interface. Abstract base classes will also have few member variables, preferably none at all.
For example, a shape is a conceptual object whereas a rectangle, triangle or circle are actual objects. As such they can all be derived from shape. The shape base class need only declare the interface that is common to all shapes, such as Draw(), Rotate(), Mirror() and so on. But since a shape doesn't have enough information to implement these methods, they must be declared pure-virtual. This ensures that shape cannot be instantiated (since it would be meaningless) and that every object derived from shape not only has a common interface, but that each type of shape provides its own specific implementation of those methods. This is not unlike overriding standard virtual functions, however the difference is that you must override the pure-virtual methods; it is not optional unless the derived class is intended to become abstract itself.
Why a friend function cannot be used to overload the assignment operator?
Assignment(=) operator is a special operator that will be provided by the constructor to the class when programmer has not provided(overloaded) as member of the class.(like copy constructor).
When programmer is overloading = operator using friend function, two = operations will exists:
1) compiler is providing = operator
2) programmer is providing(overloading) = operator by friend function.
Then simply ambiguity will be created and compiler will gives error. Its compilation error.