What are the different types of codes in c plus plus?
You can create an infinite type of classes in C++, memory permitting of course. Defining a class does not actually consume any memory, just as defining any user-defined type does not physically consume memory -- memory is only consumed when you instantiate an object of the class, just as instantiating a variable from a type consumes memory, not the type itself. However, you do need disk-space to store the files in which you declare your types, thus the number of unique types you can declare is ultimately determined by the amount of free storage space you have. Aside from that the only limit is your imagination and how you classify your objects (which is, after all, the whole point of declaring classes in the first place).
What do you mean by type conversion in c plus plus?
A no converting type cast is a type cast where the underlying data type is intrinsically the same as the type being cast, thus no conversion is required. This will often occur when explicitly converting from one type definition to another when both are in fact the same definition.
For instance, type casting from an unsigned int to a size_t is a no converting type cast because the size_t data type is merely a type definition (typedef) for an unsigned integral. Thus type casting between any of the following would result in a no converting type cast:
unsigned
unsigned int
unsigned long
unsigned long int
size_type
size_t
Note that unsigned and long are both modifiers, not types. If you omit the type, int is assumed, thus the first four are fundamentally unsigned int.
Note also that a conversion and a type cast are not really the same thing, but they do similar jobs. A conversion is an implicit conversion between types while a type cast is an explicit conversion between types. In other words, they're both conversions, but not all conversions are type casts.
This is best demonstrated with some examples:
int i = 3;
In the above example, the literal constant 3 is implicitly int, thus this is an example of a no conversion type cast (same fundamental type).
long j = long (i);
The above example is also a no converting type cast because int and long are fundamentally the same type. Remember, long is a modifier, not a type in its own right, thus long int is implied, and a long int is fundamentally the same as an int.
unsigned int k = i;
The above example is an implicit conversion because the value of i (3) is assigned to a fundamentally different type to that of i.
unsigned int l = (unsigned int) i;
unsigned int m = static_cast<unsigned int> (i);
The above examples are explicit conversions (type casts). Both explicitly cast the integral 3 to an unsigned int.
Explicit conversion (type casting) between primitive types is usually unnecessary because the compiler knows how to convert between these types and it's generally not something the programmer need overly concern themselves with. However, it can sometimes be important to highlight the fact that a conversion is taking place. In these cases it is best to be explicit and the static_cast operator is the best way of making the cast stand out. Conversion to or from more complex objects should be handled by the object's themselves through class conversion operators that implement static_cast where appropriate, and dynamic_cast or reinterpret_cast when the conversion is more complex. Again, it can be important to highlight the fact a conversion is taking place so it's best to keep conversion operators to the absolute minimum and force consumers to be explicit with their conversions. You can also use const_cast to highlight the fact that the constness of a type is being converted.
What Programming language is one step above machine language?
I guess you're trying to refer to Assembly language.
C plus plus program for linear search non-recursive method?
#include
#include
#include
void main(){
int arr[100],i,element,no;
clrscr();
printf("\nEnter the no of Elements: ");
scanf("%d", &no);
for(i=0;i printf("\n Enter Element %d: ", i+1); scanf("%d",&arr[i]); } printf("\nEnter the element to be searched: "); scanf("%d", &element); for(i=0;i if(arr[i] == element){ printf("\nElement found at position %d",i+1); getch(); exit(1); } } printf("\nElement not found"); getch(); } Output: Enter the no of Elements: 5 Enter Element 1: 12 Enter Element 2: 23 Enter Element 3: 52 Enter Element 4: 23 Enter Element 5: 10 Enter the element to be searched: 23 Element found at position 2
What is the difference between array of pointers and pointer to an array?
An array of pointers is that for eg if we have array of 10 int pointers ie int *a[10] then each element that which is stored in array are pointed by pointers. here we will have ten pointers. In pointer to an array for eg int(*a)[10] here all the elements that is all the ten elements are pointed by a single pointer.
What is the c plus plus program that finds max value in the array of size n?
#include
using std::cout;
using std::endl;
double maxValue(double arr, const intarrSize);
int main()
{
const int arrSize = 10;//Size of the array you are going to use
double arr[arrSize] = {0.0};
cout << endl << "Enter the array elements..."
for ( int i = 0; i < arrSize; i++ )
{
cout << endl << "Enter " << (i + 1) << " element:";
cin >> arr[i];
}
cout << endl << "Max value is: " << maxValue;
system("PAUSE");
return 0;
}
double maxValue(double arr, const intarrSize)
{
double max = arr[0];
for ( int j = 0; j < arrSize; j++ )
{
if ( max < arr[j])
{
max = arr[j];
}
}
return max;
}
If the seminal fluid is infected, even a microscopic amount of it can transmit disease.
None at all. All that is needed for a Sexually Transmitted Disease is close skin to skin or oral contact. Particularly more so when it invoves the genital areas. Penetration or ejaculation are not necessary for the transmission of many STD.
When do preprocessor directives execute in c plus plus?
Preprocessing is the first stage of compilation, where macros are expanded, conditional compilation established and code replaced according to the specified directives. The resulting code produces intermediate source files which are then compiled by the main compilation process. Your IDE may include options to retain these intermediate files so you may examine them.
What are the differences between a struct data type and a class data type in c plus plus?
A struct declares all members public by default, whereas a class declares all members private by default. That is really the only difference. Structs are from C and classes from C++, you can use both structs and classes in C++ but only structs in C.
How does C plus plus program write in Visual studio?
You begin by writing the source code. Any errors at this stage (syntax time) must be fixed before proceeding further. The IDE (integrated development environment) will usually highlight syntax errors as they occur.
When the source code is ready it can be compiled. Any errors at this stage (compile time) must be fixed before compilation can complete. Again, the IDE should highlight these errors.
Successful compilation creates individual object files which can then be processed by the linker. Any errors at this stage (link time) must be fixed before an executable is created. Once again, the IDE will assist you.
Once the executable is created it can be run. Any errors at this stage (run time) must be fixed before code is finally ready to ship. The IDE won't help you unless you make a debug version of your executable, which can then be debugged in your IDE to locate logic errors, unhandled exceptions, etc. When the debug version works as expected, you can build a release version. After a final check for run time errors, the program is complete. Don't delay. Ship it!
Although there are many stages to creating an executable, the IDE can reduce the workload by creating a MakeFile for your project, which automatically builds the application for you (both debug and release versions) only stopping when an error is encountered.
If your source code includes conditional compilation for a variety of platforms and architectures, the source must be compiled separately for each using the intended platform for each.
What is different is pop and oop in c plus plus?
pop the work is done with the help of functions and more previlage is given to function and not the data, also you dont have data hiding,operator overloading, function overloading, access specifiers and inheritance features in pop and when your business logic expanded pop was not able to meet the required demand and because of this oops came inot action where in oops data used to get more importance,data hiding is possible with the help of access specifiers. Each object controls it's own data, Inheritance is possible and many more features are available
Example of pop is :c,fortran
Example of oops is: java,C#
Write a c plus plus program to find the area of circle?
#include<stdio.h>
void main()
{
int r;
int pi=3.14;
float cir,area;
printf("/n enter the radius of the circle");
scanf("%d",&r);
cir=2*pi*r;
area=pi*r*r;
printf("the circumference of the circle is%d",cir);
printf('the area of the circle is %d",area);
}
Algorithm to insert and delete an element from a circular queue?
The Method To Add an element in Circular Queue
# define MAXQUEUE 100 struct queue{
int items[MAXQUEUE];
int front, rear;
}
struct queue q;
q.front=q.rear=MAXQUEUE -1;
void ENQ(struct queue *pq, int x)
{
/* make room for new element*/
if(pq ->rear = MAXQUEUE - 1)
pq-> rear = 0;
else
(pq->rear)++;
/* check for overflow */
if(pq ->rear==pq->front)
{
printf("queue overflow);
exit(1);
}
pq->items[pq->rear]=x;
return;
}/* end of ENQ*/
A Method to Delete an element from Circular Queue
int DQ(struct queue *pq)
{
if(pq-> rear == pq-> front)
{
printf("queue underflow");
exit(1);
}/*end if*/
if(pq->front = = MAXQUEUE-1)
pq->front=0;
else
(pq->front)++;
return(pq->items[pq->front]);
What is the use of header file in c?
A header file is used to define constants, variables, macro's and functions that may be common to several applications. When a system consists of multiple applications that all access the same data it becomes essential that each application uses identical definitions and it is safer for all of those applications to use the same methods to read that data. updating data should only be performed by a single function, from a single application, but reading data can be safely performed by using the common defintions found in header files. you use header files in the programming language C to declare struct's functions and other things that could be usefull for your program.. it makes thing's simpler and easy to use...
What are the difference between array declaration in java and c plus plus?
There is no difference, other than that declarations in C++ can also initialise the variable in a single instruction.
C example:
int x; // declaration
x=5; // initialisation
C++ example:
int y=5; // declaration and initialisation combined.
Is Java or C plus plus faster?
Java is considerably more convenient than either C or C++ due to its extremely high level of abstraction. However, that convenience comes at the cost of both performance and efficiency.
How an object of a class that contain object of other class created in C plus plus?
An object is a thing that occupies memory, has a value, and has methods that manipulate it. As such, even elementary variables are objects.
Most, however, consider that an object in C++ is an instance of a class type.
// declaration and definition
class myClass {
... attributes
... methods
... constructors
... destructor
};
// instantiation by direct allocation
myClass myClassObject;
// instantiation by heap allocation
myClass *myClassObjectPtr = new myClass;
How do you write a program in c plus plus to swap each half of an array?
Swapping array elements is simple enough. The only issue is what to do with the middle element when there are an odd number of elements. The following program simply leaves it where it is.
#include<iostream>
#include<vector>
template<typename T>
void exchange (std::vector<T>& v)
{
if (v.size()<2) return;
size_t left = 0;
size_t right = v.size() / 2;
if (v.size()%2)
++right; // skip middle element
while (right < v.size())
std::swap (v[left++], v[right++]);
}
int main()
{
std::vector<unsigned> v {4, 8, 15, 16, 23, 42, 69};
for (auto n : v) std::cout << n << ' '; std::cout << std::endl;
exchange (v);
for (auto n : v) std::cout << n << ' '; std::cout << std::endl;
}
How t print a table in tabular form in two dimensional array in c plus plus?
#include<iostream>
#include<iomanip>
#include<vector>
#include<random>
#include<ctime>
using data_t = std::vector<std::vector<int>>;
size_t get_width (int num)
{
size_t width=1;
while (num/=10)
++width;
return width;
}
std::vector<size_t> get_column_widths (const data_t& data)
{
std::vector<size_t> width;
for (auto row : data)
{
if (width.size() < row.size())
width.resize (row.size());
for (size_t i=0; i<row.size(); ++i)
{
size_t w = get_width (row[i]);
if (width[i]<w)
width[i]=w;
}
}
return width;
}
void print_table (const data_t& data)
{
using std::cout;
using std::endl;
using std::right;
using std::setw;
std::vector<size_t> width = get_column_widths (data);
cout << right;
for (auto row : data)
{
for (size_t i=0; i<row.size(); ++i)
{
cout << setw(width[i]) << row[i] << ' ';
}
cout << endl;
}
}
int main()
{
// Random number generator (range: [1:1000])
std::default_random_engine generator ((unsigned) time (0));
std::uniform_int_distribution<unsigned> distribution (1, 10000);
// Create a 10x5 matrix:
data_t data;
for (size_t row=0; row<10; ++row)
{
data.push_back (std::vector<int>{});
for (size_t col=0; col<5; ++col)
data[row].push_back (distribution (generator));
}
print_table (data);
}
How do you write c plus plus program to insert an element into a binary search tree?
Binary Search is an algorithm that finds an element by successively halving the search space. Typically, pointers are used, one for the beginning of an array, one for the end. Then a midpoint pointer is chosen, and a test is performed. You either find the element, or you discover that the target element is before or after the midpoint. You then adjust either the start pointer or the end pointer and you iterate. When you reach the point where the pointers are out of order, you conclude that the target is not found, and you also know where to insert it. Binary Search is best implemented with an ordered array, because you want to make "random" access to each element. The problem with arrays is that they are typically fixed size, and must be dynamically adjusted when they need to grow, a potentially "expensive" operation. You can also implement a Binary Tree, but there is cost in development and processing. Even trees have issues because, when inserting and deleting elements, you must use a rebalancing algorithm, otherwise the tree might degrade to a linked list, which is not efficient when used as a search space. In C++, it is possible to declare and define a class of elements that you can add to, subtract from, and search. If you do this correctly, you could start with a static or dynamic array, and then upgrade if need be to a binary tree, and then upgrade if need be to a balanced binary tree, all the while without requiring change to the public interface. That is perhaps the most important value of an Object Oriented Language such as C++.
What is a label in c plus plus?
A label is simply a user-defined name that appears on its own line and is followed by a colon. Labels are used with goto statements. Labels are also used with switch statements, where each case label is an unique label that represents the result of the expression evaluated by the switch statement. Labels are ignored by the code that immediately precedes them, they are only used to mark the address of the code that immediately follows.
What is Matrix addition in c plus plus?
Matrix addition is simply the process of summing one array to another array of the same size. The result is another array of the same size where each element is the sum of the corresponding elements in the first two arrays, like so:
{1, 2, 3} + {4, 5, 6} = {1+4, 2+5, 3+6} = {5, 7, 9}
This can be extended to multi-dimensional matrices (an array of arrays):
{1, 2, 3}
{4, 5, 6}
+
{7, 8, 9}
{10, 11, 12}
=
{7+1, 8+2, 9+3}
{10+4, 11+5, 12+6}
=
{8, 10, 12}
{14, 16, 18}
To achieve this in C++, C-style static arrays are the easiest method:
int main()
{
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
int b[2][3] = {{7, 8, 9}, {10, 11, 12}};
int c[2][3] = {{0, 0, 0}, {0, 0, 0}};
for (size_t row=0; row<2; ++row)
for (size_t col=0; col<3; ++col)
c[row][col] = a[row][col] + b[row][col];
}
C-style dynamic arrays as well as std::vector and std::array can also be used to represent the matrices, but it is important that all dimensions are the same. Matrices of different sizes cannot be added together (the result is undefined).
When do we make a virtual function pure?
We make a virtual function pure whenever we wish to make our class an abstract base class (an abstract data type). Unlike a virtual function, pure virtual functions must be overridden by a derived class or by one of its derivatives (the function remains pure virtual until it is overridden, at which point it becomes virtual). Derived classes that do not provide a complete implementation for all the pure virtual functions it inherits become abstract themselves. You cannot instantiate an abstract base class other than through derivation.
To find the largest element of an array in c plus plus?
int GetMaxElement( void * array)
{
if (array != 0)
{
return(max(array[], typeof(array)));
}
return(0);
}
Is c or c a procedural oriented language?
One definition of a "procedural programming language" is a language that is used to describe how a program should accomplish the task it is to perform. This is in opposition to a "declarative programming language" that is used to describe what the program should accomplish rather than how it accomplishes the task.