Overloads cannot differ by return type alone. The only way to achieve this is to use output arguments. Since the implementation is exactly the same regardless of the output type, you can use a function template to generate the overloads.
#include<iostream>
#include<sstream>
template<typename T>
bool convert(std::string& s, T& value)
{
std::stringstream ss;
ss << s;
if (ss >> value)
return true;
return false;
}
int main()
{
int i;
float f;
std::string s {"3.14"};
if (convert (s, i))
std::cout << '"' << s << "" = " << i << std::endl;
if (convert (s, f))
std::cout << '"' << s << "" = " << f << std::endl;
}
Output:
"3.14" = 3
"3.14" = 3.14
What is adapter in programming language?
An adapter is a class that subclasses a commonly used class or interface with reasonable default functions provided. For example, the WindowAdapter provides a quick solution that provides default do-nothing functions for 4 common interfaces that a GUI would use. Typically, a developer only needs one or two functions from WindowEvent, for example, but without an adapter, they are required to implement seven functions (with five or six of them "do-nothing" functions), instead of just using an adapter and providing the one or two function bodies they do need.
There are several ways to implement this, however the basic principal is to sort the doubles in ascending order and return the middle element (in this case the 2nd element). The simplest implementation uses a 3-element array which is then sorted using an insertion sort, as shown in the following example.
#include<iostream>
#include<list>
double median(double& x, double& y, double& z)
{
// initialise the array
double a[3] = { x, y, z };
// sort the array
for(int i=1; i<3; ++i)
{
int hole=i;
int prev=hole-1;
double cur=a[hole];
while(hole && cur<a[prev])
{
a[hole]=a[prev];
--hole, --prev;
}
a[hole]=cur;
}
// return the middle element.
return( a[1] );
}
int main()
{
using namespace std;
double a, b, c;
a = 0.9;
b = 0.1;
c = 0.5;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
cout<<"median="<<median(a,b,c)<<endl;
return(0);
}
Output:
a=0.9
b=0.1
c=0.5
median=0.5
It should be noted that when dealing with an even number of elements (such as 4 or 6), then there is no middle element, so you therefore need take the mean of the two middle elements instead. So if the sorted numbers are 0.1, 0.2, 0.5 and 0.9, then the median is the mean of 0.2 and 0.5, which is 0.35 (e.g., ( 0.2 + 0.5 ) / 2).
What is SDLC?
A software cycle deals with various parts and phases from planning to testing and deploying. All these activities are carried out in different ways, as per the needs. Each way is known as a Software Development Lifecycle Model (SDLC)
What are the different SDLC Models ?
1.Rapid application development(RAD) (including methods like SCRUM, Agile & Extreme Programming);
2.The linear or waterfall model(which was the original SDLC method);
3.Joint application development (JAD);
4.The iterative model;
5.The v-model;
6.The prototyping model;
7.The fountain model;
8.The spiral model;
9.Build and fix;
10.synchronize-and-stabilize
What tools are provided by Microsoft Visual C plus plus?
VC++ is packed with tools including error lookup and ATL/MFC trace amongst many others. The Windows SDK adds a few more tools, as does SQL server and any other supported development tools. You can also create your own tools and add third-party tools, such as Axialis IconWorkshop, resource editors, help file/documentation editors and so on. Many developers have produced many useful (and expensive) development tools for VC++ over the years so if you can't find a particular tool that meets your requirements on the Internet then it simply doesn't exist.
Are single people a protected class?
No.
Protected class people are popularly known as Diversity or multicultural people.
American Diversity protected class people include...
Afro-American
Women
Jewish
LGBT
Hispanic & Latino
Asian
Disabled
Native American
Protected class people are historically oppressed by the white supremacist - white-male-gentile-straight-gringo-occidental-ablebodied-settler.
What facility static gives in class?
Static variables or function provides global view to the application that is u can access a static variable with one or more than one objects of a single class without loosing i.e. reinitializing its value.
What is the purpose of the header file io.h in c plus plus?
The header, io.h, is part of the standard C library and contains declarations for file handling and I/O functions. The file has no practical purpose in C++; it is only included because it was required prior to C++ standardisation. However, it can be used when writing C-style programs and libraries in C++.
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
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.
#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");
// ...
}
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.