What is the code for date validation in c plus plus?
You need to check the day, month and year separately, to ensure they are within range. You also need to deal with leap days (29th February) which is every 4 years, but not the 100th unless it is the 400th. Finally, you need to deal with the change from the Julian to Gregorian calendars, which skips the 5th to 14th October, 1582.
bool checkdate(unsigned int d, unsigned int m, unsigned int y)
{
return( !(( d<1 d>31 m<1 m>12 ( y==1582 && m==10 && (d>4 && d<15 )))
( d==31 && ( m==2 m==4 m==6 m==9 m==11 ))
( m==2 && ( d>29 ( d==29 && ( y%4 ( !( y%100 ) && y%400 )))))));
}
How do you get the array values in C plus plus?
Use the array suffix operator ([]), or use a pointer offset from the start of the array, such that an offset of 1 is equivalent to the size of an array element (all elements in an array must be of equal size). The latter method is what actually goes on behind the scenes when using the array suffix operator, but the former is generally easier to use.
What are 4 valid variable types in C plus plus?
long, short, char and bool are 4 valid variable types. There are many more available, including (but not limited to) float, double, int, wchar_t, size_t, as well as compound types (such as long long) and unsigned/signed variations, such as unsigned int. All of these types are primitive, integral or built-in data types. More complex data types can be formed from struct, class and union declarations, but they all simply build upon the integral types.
How can you pause or break a C plus plus program running in DOS-BOX?
There is no pause function as such, but you can easily roll your own:
#include <iostream>
#include <limits>
void Pause()
{
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
int main()
{
Pause();
return( 0 );
}
What is the type of class for which object cannot be created?
A class that is declared as "final" cannot be inherited.
#include<iostream.h>
void main(void)
{
int n;
cout<<"Enter A Value For Triangle:"<<endl;
cin>>n;
cout<<endl;
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
cout<<" ";
for(int k=2*n;k>=2*i;k--)
cout<<"*";
cout<<endl;
}
cout<<endl;
cout<<endl;
for(int l=0;l<=n-4;l++)
cout<<" ";
cout<<"ENJOY"<<endl<<endl;
}
How do you create an object type object in c plus plus?
An object is simply an instance of a class.
#include<iostream>
class my_object {};
int main()
{
my_object X; // instantiate an instance of the class my_object, identified as X.
}
Definition of loop and its types and programs in c plus plus?
Executing a segment of a program repeatedly by introducing a counter and later testing it using the if statement.
A sequence of statements are executed until some conditions for termination of the loop are satisfied.
A Program loop consists of two segments:
1.Body of the loop
2. Control Statement
Depending on the position of the control statement in the loop, a control strcture may be classifies either as the 2:
What is copy construct in c plus plus?
A copy constructor is a separate, compiler created constructor for a class. This allows the programmer to instantiate a class and copy the contents of the given class into the new class. For example:
If I have a class foobar:
Foobar foobar;
Foobar foobar1( foobar );
The second line creates a class in the exact image of the original class, with all of its variables set the same way as the original class.
What is a do while statement in c plus plus?
A do-while statement is a type of loop that iterates while a condition remains true. The condition is evaluated at the end of each iteration, thus the statement always executes at least once.
do {
statement;
} while (expression);
What is overloading function in c and explain with example?
Short answer: You can't.
Long answer: Function overloading is when you define two functions with the same name that take different arguments, e.g.:
void pickNose(int fingerId);
void pickNose(Finger finger);
This is a valid construct in C++, which supports function overloading. If you try this in C, you'll get some error about function already defined.
What is the importnce of file handling?
Most applications cannot operate efficiently (or sometimes even at all) without some method to save and load data of some sort. While a database may suffice in many cases, in others it's impractical (either because availability of a DBMS isn't guaranteed, the data stored isn't enough to justify the added overhead, etc.) In such cases, using a file of some sort is often the only other reasonable option. Doing so requires file handling commands to open and close the file, read from and write to the file, etc.
What supports reusability and extensibility of classes in c plus plus?
There are two ways to reuse a class in C++. Composition and inheritance. With composition, any class data member can be an instance of an existing class. With inheritance, we can derive a new class from an existing class. Either way, we create a new class of object with all the properties of the existing class which can be extended and/or replaced with properties of our own.
How do you handle object array?
Exactly as you would any other type of array. An object's size is determined in the same way a structure's size is determined, by the sum total size of its member variables, plus any padding incurred by alignment.
However, you cannot create arrays of base classes. Arrays of objects can only be created when the class of object is final; a class that has a private default constructor, otherwise known as a "leaf" class. This is because derived classes can vary in size; array elements must all be the same size.
To create an array of base classes you must create an array of pointers to those base classes instead. Pointers are always the same size (4 bytes on a 32-bit system).
Static arrays are ideally suited to arrays of leaf objects where the number of objects never changes, or the maximum number of objects is finite and fixed. Although you can use dynamic arrays of leaf objects, you will incur a performance penalty every time the array needs to be resized, because every object's copy constructor must be called during the reallocation. Dynamic arrays are better suited to arrays of pointers to objects -- only the pointers need to be copied during resizing, not the objects they point to.
How is dynamic initialisation achieved in c plus plus?
The C++ standard has this to say about dynamic initialisation:
"Objects with static storage duration shall be zero-initialised before any other initialisation takes place. Zero-initialisation and initialisation with a constant expression are collectively called static initialisation; all other initialisation is dynamic initialisation."
How do you make chess game in c plus plus programming?
This question cannot be answered here. Go to amazon.com and find a book about chess-programming.
Who created c and c plus plus and java?
Dennis Ritche developed C for bell labs for the unix operating system http://en.wikipedia.org/wiki/C_(programming_language) Bjarne Stroustrup developed C++ http://en.wikipedia.org/wiki/C%2B%2B
How do you increment date using strdate in c plus plus?
In short, you don't.
The strdate() function returns a formatted string that represents the current date. It is not intended that this result be used in a date calculation such as increment. The complexities of converting back to month day and year, and then dealing with the special rules of the Gregorian calender, along with leap years is unrealistic, given that there are library functions that will do this for you already. Try this...
#include <time.h>
#include <iostream>
using namespace std;
...
char cdate[9];
time_t tt = time(NULL) + 86400; // tomorrow
struct tm *tomorrow;
tomorrow = localtime (&tt);
strftime(cdate, 9, "%m/%d/%y", tomorrow);
cout << cdate << endl;
What is the difference between abstract class and normal class?
Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods.
We cannot create an object for the abstract classes.
When we inherit the abstract class we should implement the abstract method which we inherit.
How do C and C plus plus differ in terms of data abstraction and classes and structs?
They differ insofar as C does not use object-oriented programming at all -- there are no classes (only structures), therefore there was nothing to abstract. C++ (which literally means 'the successor to C') is an extension of C that primarily adds object-orientated support to the language. Everything you can do in C you can also do in C++, but with the added benefits of OOP you can do a whole lot more, more easily, including the creation of abstract data types.
Why enumerator data type is used in c plus plus?
Enumerated data types are a set of user-defined constants called enumerators that provide context to a range of values. For instance, if you define the following constants:
static const int Monday=0;
static const int Tuesday=1;
// ...
static const int Sunday = 6;
static const int January=0;
static const int February=1;
// ...
static const int December=12;
Then there's nothing to prevent you from coding the following:
int var1 = January;
int var2 = Tuesday;
// ...
int var3 = var1 + var2;
What exactly does var3 represent? A month? A day? Or something else entirely? The problem is the compiler can't help you because you've not actually done anything wrong. As far as the compiler is concerned, all you've done is add two ints together to produce a third int. Whether it makes sense or not is another matter altogether.
Enumerations exist to prevent this sort of problem.
enum day { Monday, Tuesday, ..., Sunday };
enum month { January, February, ..., December };
month var1 = January;
day var2 = Tuesday;
// ...
int var3 = var1 + var2;
Now the compiler will tell you there is no suitable plus operator that accepts an l-value of month and an r-value of day.
Enumerators have an implied type of signed int, but you can also specify an alternative type, provided it is an intrinsically primitive integral type, such as int, char, or short, whether signed or unsigned. However, even when typed, you cannot use any operators upon them unless you specifically provide an operator overload to cater for them. Thus the following will not work:
for( day d=Monday; d<=Sunday; ++d )
// ...
Without a suitable operator overload for the prefix increment operator, you must use an explicit cast, such as follows:
for( int i=Monday; i<=Sunday; ++i )
{
day d = reinterpret_cast<day>(i);
// ...
}
Although you've got to work a bit harder to use enumerators, the point is that the additional work is required in order to prevent problems such as those highlighted at the start of this answer. Enumerators enlist the compiler to help you spot errors, forcing you to make a conscious decision whenever you want to override the compiler's help, but ultimately ensuring your code is as robust as possible.
What is a sparse matrix in c programming?
Sparse matirx can be represented 1-dimensionally, by creating a array of structures, that have members sumc as: Struct RM{int ROW,int COL, int non_zero}; struct RM SM[Number_non_Zeros +1]; then input row,col for each non-zero element of the sparse matrix. if still unclear please fell free to requestion or query on ikit.bbsr@gmail.com, specifying clearly the question in the subject. Chinmaya N. Padhy (IKIT)
What are the limitations of friend function?
Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope.
Friends are used to extend the interface of a class. They are useful in that certain classes and functions may require private access to other class members, particularly where two classes are closely coupled (such as parent and child classes).
Friends should never be used when suitable interfaces already exist. If you have to expose an interface simply to allow an external function or class to do its job, then it would be better to declare the function or class a friend rather than expose an otherwise unnecessary interface. The key to good encapsulation is to minimise your interface as much as possible -- only expose what you absolutely must expose.
Before allowing friendship, always consider whether the function or class can be declared a member of the class itself. Static member functions are often a good choice here. However, certain functions, such as stream insertion and extraction overloads, cannot be implemented as member functions and must be implemented as external functions. These are often cited as good examples of friend functions, however keep in mind that when suitable interfaces exist, friendship is unnecessary.
Although friends are not members of the class that declares them to be a friend, they must be treated just as if they were members. That is, you must have full control over the implementation in order to maintain encapsulation. But keep in mind that the purpose of a friend is purely to gain private access for which no public interface exists and where providing such an interface would do more to undermine your encapsulation than a friend would.
When should a member of a class be declared public?
When the member needs to be accessible from outside of the class. Private members are only accessible from within the class itself, including friends of the class. Protected members are the same as private members but are also accessible to derived classes. Derived classes therefore inherit both the protected and public members of its base classes.