What is the difference between a string and an array?
Nothing whatsoever. A string is simply an array of type char.
In some programming languages, such as C, a string is an array of char (or short), terminated with a null \0.
An array is just a fixed size of collection, a container to hold things/objects. If all the elements in the container are characters (of char), then we may call it a string, sometimes a byte array (because each character can be represented as a byte).
An array of 7 different days, it maybe a WEEK, or just the birthdays of 7 dwarfs. Then they are nothing to do with strings.
A data item (or variable) is described as a "string" type when it contains some number of characters. Those characters can usually be anything in the system's accepted list of codes. Most systems use ASCII, so a string can include the letters a-z, A-Z, numbers 0-9, and special characters like ~!@#$%^&*()_+-=[]\{}|:";'<>?,/. A string is treated as a single object, although most programming languages have methods to break strings apart (called sub-stringing). In the Perl language, strings are named $something.
An array is a collection of individual data items, sort of like a list. Each element in an array can be referred to in a program by its position in the list. In the Perl language, an array would be named @SOMETHING. The first element in the array would be named $SOMETHING[0], the second $SOMETHING[1], and so on. Each element can be a string, or some other data type.
Other data types would be integers (positive or negative whole numbers), floating point (decimal numbers like 3.14159 or 2398.41; it can be more complicated than this, but that's another story), and a few more exotic types.
In the C programming language a string is actually the same as an array of characters. The last character in a C string is a zero byte which indicates the end of the string.
C plus plus program to find all even numbers between 100 and 150 using for loop?
#include
int main(){
int i;
for(i=2;i<=100;i=i+2){
printf("%d\n",i);
}
}
Why would you write a program using array processing linear search and binary search of an array?
Linear search sample data: 8 3 9 12 4 10 38 2 1 93 56 34
Binary search sample data: 1 2 3 4 8 9 10 12 34 38 56 93
In the first set of data, unsorted data cannot be searched using binary search. To find the value 38, a program must go through each element until it locates the 7th element; this is a total of 7 iterations. This method is effective when data is constantly being added and removed, and the overhead of a sorting algorithm would be less efficient than a binary search.
In the second set of data, the value 38 can be found by binary search. In the first iteration, a binary halfway point is found (we will choose element 6). Since 9 is less than 38, we know we need to go up. There are six remaining values, so we look at the 9th element (starting from the 6th element, there are six more, so we go half-way, 3 more, a total of 9). Here, we see the value is 34, still less than 38. There are three values remaining, so we go up 2 more. For the third iteration, the value is 56, which is more than our target of 38. Since we advanced 2 last time, we will decrease by 1 this time, and our fourth iteration will find the value 38.
As a matter of fact, in this data set, we will always find our answer in at most 4 iterations, while in the linear search, only the first 4 elements have a chance of being more efficient than the binary search. The problem then comes to down to if the sorting and binary search combined is faster than the linear search. For large data sets that are mostly static, binary searching is preferred. For rapidly changing data sets that would need constant sorting, a linear search may be preferred.
Note that if the data insertion algorithm maintains the sort order (by inserting each element at the correct index in memory), binary searching will likely be faster in the majority of cases. One can use a binary search for data insertion points, keeping the cost of data insertion minimized (but not as efficient as simply appending to the end) while maximizing search capabilities.
Is there any pointer called ds cs es ss pointer in C programming?
yes, ds cs es ss are pointers available in c which is used to refer memory segments
How do you determine class width?
Not sure what you mean by class width, but if you mean how do you determine the size of a class, the simplest way is to use the sizeof() operator. The value returned may be equal to or greater than the sum of all its member variables, depending on any adjustments made for memory alignment. If the class contains pointers to memory allocated on the heap, this memory will not be included in the total -- only the size of the pointers to those allocations will be considered.
EDIT: Previous answer does not address the question.
#include<stdio.h>
main()
{
int n,m,i,max;
printf("How many numbers(n) you going to enter:");
scanf("%d",&n);
printf("Enter the numbers:");
scanf("%d",&m);
max=m;
for(i=2;i<=n;i++)
{
scanf("%d",&m);
if(m>max)
max=m;
}
printf("The Largest Number is %d",max);
}
Output:
How many numbers(n) you going to enter:5
Enter the numbers:
25
410
362
5
56
The Largest Number is 410
#include<list>
#include<string>
struct Customer
{
std::string m_name;
std::string m_phone;
Customer (std::string name, std::string phone): m_name(name), m_phone(phone) {}
// ...
};
int main()
{
std::list<Customer> customers;
customers.push_back ("Joe Bloggs", "555 7465");
customers.push_back ("Dan Mann", "555 3458");
// ...
}
Can a string value be enclosed in double quotes?
Yes, that is the standard in many programming languages.
Yes, that is the standard in many programming languages.
Yes, that is the standard in many programming languages.
Yes, that is the standard in many programming languages.
The constructor. The constructor instantiates the object, and can optionally take parameters and has an optional initialization phase.
It has no return type, and has the same name as the class itself.
The constructor can be overloaded. It cannot be virtual or constant.
What is difference between wait and sleep and delay in C plus plus?
It depends on the particular library implementation. It is not a C++ specific question. As far as C++ is concerned, it is just a function call, just like a call to printf or even exit is a function call.
One could be a call to wait for an event.
One could be a call to sleep for a specified period of time.
One could be a call to burn CPU cycles for a specified period of time.
Again, it all depends on the library implementation, and you need to read the documentation for your library to answer this one.
Explain the difference between for and while loop and give the suitable examples in c plus plus?
There is no actual difference; a for loop is just syntactic sugar for a while loop. Which you use depends largely upon which makes the most sense within the context of your source code. The for loop is clearly more flexible, but you will generally use a for loop whenever the number of iterations is known in advance, such as when counting iterations, whereas while loops are generally used whenever the number of iterations is unknown or infinite. Regardless, this has no effect on the efficiency of your code (the machine code maps almost directly, 1-to-1, with a while loop), it's just a question of which makes your code easier to read.
One useful property of a for loop is that you can declare and initialise a control variable in the initial expression. This renders the control variable local to the loop, which is something you cannot achieve with a while loop. This has no effect on the resultant machine code, but by scoping variables within a for loop you automatically enlist the help of the compiler to eliminate bugs.
It should be noted that the do-while loop is similar to a while loop, except that a do-while loop always executes its statements at least once, because the conditional expression is evaluated at the end of each iteration, rather than before each iteration as it is with a while loop. Again, a for loop can be used to achieve a do-while loop, however the do-while loop maps closely with the resultant machine code, and is generally much easier to read.
Which key element will be best for merge sort and why?
There is no key element in a merge sort. Unlike quick sort which requires a key element (a pivot) to recursively divide a subset into two subsets, merge sort simply divides a subset into subsets of 1 element and merges adjacent subsets together to produce sorted subsets. When there is only one subset remaining, the subset is fully sorted.
It means Terminate-Stay-Resident. A TSR is a program that remains in memory when the program ends.
Where can you get the mseb bill generation project in c plus plus?
No such code exists for MSEB Bill Generation in C++.
What is array passer c plus plus?
//Array Passer
//Demonstrates relationship between pointers and arrays
#include
<iostream>
using
namespace std;
void
increase(int* const array, const int NUM_ELEMENTS);
void
display(const int* const array, const int NUM_ELEMENTS);
int
main()
{
cout <<
"Creating an array of high scores.\n\n";
const
int NUM_SCORES = 3;
int
highScores[NUM_SCORES] = {5000, 3500, 2700};
cout <<
"Displaying scores using array name as a constant pointer.\n";
cout << *highScores << endl;
cout << *(highScores + 1) << endl;
cout << *(highScores + 2) <<
"\n\n";
cout <<
"Increasing scores by passing array as a constant pointer.\n\n";
increase(highScores, NUM_SCORES);
cout <<
"Displaying scores by passing array as a constant pointer to a constant.\n";
display(highScores, NUM_SCORES);
return
0;
}
void
increase(int* const array, const int NUM_ELEMENTS)
{
for
(int i = 0; i < NUM_ELEMENTS; ++i)
array
[i] += 500;
}
void
display(const int* const array, const int NUM_ELEMENTS)
{
for
(int i = 0; i < NUM_ELEMENTS; ++i)
cout <<
array[i] << endl;
}
Why can't the accessor member function change any of the values in a class in C plus plus?
Nothing stops a member function from changing any of the values in a class. By convention, an accessor function is used to give read only access to class data, but that does not mean that it is prohibited from doing so. It is a member function, after all, and it has all the rights of any member function of the class.
Does cryengine require coding?
It all depends on what you are making, if you want your own specific AI or some types of events or you simply want to make your game more diverse coding is highly recommended. Entities provided by cryengine are helpful but make for a bland game (usually). Take a look at the coding and give it a try
What is operand in c plus plus?
An operand is the value that is being operated upon by an operator. For instance, the C++ increment operator (++) is a unary operator, which means it has only one operand, the variable that we wish to increment. This in the expression x++, x is the operand. The addition operator (+) is a binary operator and therefore has two operands. Thus in the expression x + y, x and y are the operands.
Are function prototypes necessary in C and Cpp?
Yes. Without prototypes you must ensure all definitions are declared forward of their usage. This isn't always possible. Separating the prototypes from the definitions means you can #include the prototypes forward of their usage, and place the actual definitions anywhere you like.
There are two methods of casting one type to another: static casting and dynamic casting (both of which apply to pointers and references to objects). Statically casting a derived class to a base class is typesafe as the base class is guaranteed to exist if the derived class exists. However, static casting from a base class to a derived class is always considered dangerous as the conversion is not typesafe. Dynamic casting exists to cater for this scenario, however it is only possible when the base class is polymorphic (thus ensuring the required runtime information is available). If the conversion is not possible, the return value is NULL. However, it is considered bad programming practice to dynamically cast from a base class to a derived class. If the base class is polymorphic (which it must be), there is NEVER any need to dynamically cast between types. Virtual methods ensure correct behaviour. Whenever you are forced to dynamically cast from a base class to a derived class, consider redesigning the base class interface instead, as it is a clear sign of bad design. It is not dangerous, however; only static casting from a base class to a derived class is considered dangerous.
int sum(int list[], int arraySize) {
int sum=0;
for(int i=0; i<arraySize; ++i )
sum+=list[i];
return(sum);
}
Why member function of a class are generally declared as public and data members as private?
Declaring member variables (data) private ensure only the class and friends of the class have access to an object's data.
Declaring member methods (functions) public is required to provide an interface to the private data.
Usually accessor and mutator methods (get/set methods) are declared public to allow user-interaction with the data. However the data itself must remain hidden by the accessors (returned by value) otherwise there's no point in hiding the data -- there is no control. Similarly, the mutators should allow the data to be modified through a controlled interface, thus ensuring the data remains in a valid state at all times. Again, allowing a public mutator to modify the data without validation defeats the purpose of hiding the data in the first place.
Protected access is another option. This is similar to private access, but also permits access to derived classes.
A well-designed class interface should only expose as much as it needs to, and no more. If an object cannot assure its own data integrity at all times, then it is no better than a structure, which is always public by default.
Note that the general rules on class interface design are intended to help not hinder you. Many new programmers find them too restrictive, often making members public when they should really be private. They have entirely missed the point of using a class rather than a structure. That is, a well-designed interface that fully encapsulates an object automatically enlists the help of the compiler to reduce the chances of you or a third party coder from attempting an illegal operation upon the data within the object. If the data integrity can be assured at all times, then the chance of error is greatly reduced. The more complex the data, the more important this becomes.