answersLogoWhite

0

📱

C++ Programming

Questions related to the C++ Computer Programming Language. This ranges all the way from K&R C to the most recent ANSI incarnations of C++, including advanced topics such as Object Oriented Design and Programming, Standard Template Library, and Exceptions. C++ has become one of the most popular languages today, and has been used to write all sort of things for nearly all of the modern operating systems and applications." It it a good compromise between speed, advanced power, and complexity.

2,546 Questions

Where can you practice c plus plus is there a website that can be useful?

C Plus Plus, or C++ is an intermediate-level computer programming language. It was developed by Bjarne Stroustrup starting in 1979. You can practice C Plus Plus at a site such as Cprogramming.

Write c plus plus program to find the factors of a given number?

It isn't actually possible to generate factorials for negative and/or non-integer numbers.

However, a function for non-negative integers is:

unsigned int factorial(unsigned int n)

{

if(n==0)

{

return 1;

}

return n * factorial(n-1);

}

What is actually passed to a function when an object is passed to a function through a pointer?

When an object is passed to a function by pointer, a copy of the pointer's value is passed to the function. Pointers are always passed by value, but because the value is a memory address than can be dereferenced, they enable us to pass objects by reference. In languages such as C which have no concept of references, this was the only way to pass by reference. C++ introduced proper references (aliases for existing objects), thus when we want to pass by reference we can choose to use a pointer or an actual reference. Normally we'd only pass by pointer when passing an optional argument that defaults to NULL when no argument is given. Otherwise we pass by reference because references can never be NULL.

You are having Problem in c c plus plus assignment Who can help you?

Get Expert C Assignment Help at ProgrammingHomeworkHelp. 📢

Struggling with your C assignments? 🤔 Don't worry, we've got your back! 🎯

🔍 Need quick solutions for complex C programming problems?

📚 Looking for expert guidance to enhance your coding skills?

🎓 Seeking affordable and reliable C assignment help?

🌟 Your search ends here! 🌟

🎉 Introducing Programming Homework Help, your one-stop destination for top-notch C assignment assistance. Our team of experienced programmers is ready to tackle any challenge and provide you with tailor-made solutions. 🎓💼

Why choose us? 🤔

✅ Expert Programmers: Our skilled C programmers are well-versed in handling diverse assignments, ensuring you receive accurate and efficient solutions.

✅ Timely Delivery: No more missing deadlines! We value your time and guarantee timely delivery of your completed assignments.

✅ 24/7 Support: Got a last-minute query? Our customer support is available round-the-clock to address all your concerns.

✅ Plagiarism-Free Work: We take academic integrity seriously, and all our solutions are 100% original and plagiarism-free.

✅ Affordable Prices: Quality assistance doesn't have to be expensive! Our services are priced competitively to fit your budget.

Don't let C assignments stress you out! 🤯 Let our experts handle the technicalities while you focus on excelling in your studies. 📚📈

💡 Excelling in C programming is just a click away! 💡

What is escape sequence?

Escape sequence is the question of I.T related technology

Escape sequence is the question of C++ Language........

Please answer this question # defines the following character escape sequences: * \' - single quote, needed for character literals * \" - double quote, needed for string literals * \\ - backslash * \0 - Unicode character 0 * \a - Alert (character 7) * \b - Backspace (character 8) * \f - Form feed (character 12) * \n - New line (character 10) * \r - Carriage return (character 13) * \t - Horizontal tab (character 9) * \v - Vertical quote (character 11) * \uxxxx - Unicode escape sequence for character with hex value xxxx * \xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx) * \Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates

Who is the father of object oriented programming?

In 1991 Oak was created by the members of the Green Project which included James Gosling (Chief Programmer) , Patrick Naughton and Mike Sheridan.

Patenting issues gave a new name to Oke -Java

Is a while loop a pre-condition or post condition?

The while loop is a pre-condition loop.  It tests the condition at the beginning of each loop, executes the loop if it is true, and goes back to the test after executing each iteration.

What is inline function what are the advantages of using inline function?

Suppose that you wish to write a function in C to compute the maximum of two numbers. One way would be to say:

int max(int a, int b) { return (a > b ? a : b); } But calling a frequently-used function can be a bit slow, and so you instead use a macro:

#define max(a, b) ((a) > (b) ? (a) : (b)) The extra parentheses are required to handle cases like:

max(a = b, c = d) This approach can work pretty well. But it is error-prone due to the extra parentheses and also because of side effects like:

max(a++, b++) An alternative in C++ is to use inline functions:

inline int max(int a, int b) { return (a > b ? a : b); } Such a function is written just like a regular C or C++ function. But it IS a function and not simply a macro; macros don't really obey the rules of C++ and therefore can introduce problems. Note also that one could use C++ templates to write this function, with the argument types generalized to any numerical type.

Suppose that you wish to write a function in C to compute the maximum of two numbers. One way would be to say:

int max(int a, int b) { return (a > b ? a : b); } But calling a frequently-used function can be a bit slow, and so you instead use a macro:

#define max(a, b) ((a) > (b) ? (a) : (b)) The extra parentheses are required to handle cases like:

max(a = b, c = d) This approach can work pretty well. But it is error-prone due to the extra parentheses and also because of side effects like:

max(a++, b++) An alternative in C++ is to use inline functions:

inline int max(int a, int b) { return (a > b ? a : b); } Such a function is written just like a regular C or C++ function. But it IS a function and not simply a macro; macros don't really obey the rules of C++ and therefore can introduce problems. Note also that one could use C++ templates to write this function, with the argument types generalized to any numerical type.

Why a function is not defined in to another function?

A function is not deigned in to another function. It is because that would lead to dependency injection.

Sort integer numbers in ascending order using pointers?

It's hardly the most efficient way to sort integers. Integers are primitive data types, so it's actually quicker to sort the integers directly rather than point at them. Pointers just add an unnecessary level of indirection. Pointers should only be used for complex data types for which copying/moving would result in greater inefficiency than would otherwise be incurred through pointer manipulation.

#include<iostream>

#include<vector>

int main()

{

// instantiate a vector of unsorted integers

std::vector<int> v = {7,3,5,2,9,4,1,6,8};

// instantiate a vector of pointers to the integers in the vector

std::vector<int*> p;

for (size_t i=0; i<v.size(); ++i)

p.push_back (&v[i]);

// sort the pointers (uses insertion sort algorithm):

for (size_t i=1; i<p.size(); ++i)

{

int* x=p[i];

size_t gap = i;

size_t pre = i-1;

while (gap && *x<*p[pre])

{

p[gap--] = p[pre--];

}

p[gap]=x;

}

// print to prove the sorting worked:

std::cout << "Original order:\t\t\t";

for (size_t i=0; i<v.size(); ++i)

std::cout << v[i] << '\t';

std::cout<<std::endl;

std::cout << "Sorted order (by pointer):\t";

for (size_t i=0; i<p.size(); ++i)

std::cout << *p[i] << '\t';

std::cout<<std::endl;

}

Write a c plus plus program to find the square root of a number?

#include<iostream>

int main()

{

unsigned num = 25; // or use user-input to assign the value

unsigned root = sqrt ((double) num)

std::cout << "The square root of " << num << " is " << root;

}

Write a C plus plus program to convert a given number into years weeks and days?

#include<iostream>

void num_to_years_weeks_days(

unsigned num, unsigned& years,

unsigned& weeks, unsigned& days)

{

years = num / 365;

num -= years * 365;

weeks = num / 7;

num -= weeks * 7;

days = num;

}

int main()

{

unsigned years, weeks, days;

unsigned num = 1000;

num_to_years_weeks_days(num, years, weeks, days);

std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl;

num = 12345;

std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl;

}

Can you write a CPP program to displaying XOR truth table using logical AND OR and NOT?

I do not believe this is possible. The only solution I could come up with does not involve either OR or NOT, but it does use the plus and minus operators combined with the logical AND operator (more formally termed addition modulo 2, or addition without carry). The following C++ program demonstrates that the function, XOR(), correctly emulates the logical XOR operator (^).

#include

int XOR( int x, int y )

{

return(( x + y ) - ( x & y ) - (x & y ));

}

int main()

{

int x, y;

std::cout << "Truth table for 0 and 1:\n" << std::endl;

std::cout << "x y ^ XOR" << std::endl;

for( x=0; x<=1; ++x )

for( y=0; y<=1; ++y )

std::cout << x << " " << y << " " << (x^y) << " " << XOR( x,y ) << std::endl;

std::cout << std::endl;

std::cout << "Evaluation of values 0 to 4:\n" << std::endl;

std::cout << "x\ty\t^\tXOR" << std::endl;

for( x=0; x<=4; ++x )

for( y=0; y<=4; ++y )

std::cout << x << "\t" << y << "\t" << (x^y) << "\t" << XOR( x,y ) << std::endl;

std::cout << std::endl;

return(0);

}

Output

Truth table for 0 and 1:

x y ^ XOR

0 0 0 0

0 1 1 1

1 0 1 1

1 1 0 0

Evaluation of values 0 to 4:

x y ^ XOR

0 0 0 0

0 1 1 1

0 2 2 2

0 3 3 3

0 4 4 4

1 0 1 1

1 1 0 0

1 2 3 3

1 3 2 2

1 4 5 5

2 0 2 2

2 1 3 3

2 2 0 0

2 3 1 1

2 4 6 6

3 0 3 3

3 1 2 2

3 2 1 1

3 3 0 0

3 4 7 7

4 0 4 4

4 1 5 5

4 2 6 6

4 3 7 7

4 4 0 0

As you can see, the third and fourth columns are all equal, thus proving the function correctly emulates the logical XOR for values 0 to 4. The same is true for all permutations of x and y.

Note that while it is possible to use AND, OR and NOT when both x and y are guaranteed to be in the range 0 to 1 (and therefore capable of producing the truth table shown above), the function does not correctly emulate the XOR operator when x or y is neither 0 nor 1. You can test this by swapping the XOR function above with the following implementation:

int XOR( int x, int y )

{

return(( x | y ) & !( x & y ));

}

Which code i need to delete middle digit in 3 digit number in c plus plus?

If you know that the number input will always be three digits:

output = 10 * (int)(input / 100) + (input % 10);

If you want to idiot proof it (eg. too many digits):

output = 10 * (int)((input % 1000) / 100) + (input % 10);

When you need to satisfy two or more criteria to initiate an event in a program you must make sure that the second decision is made entirely independently of the first decision?

Evaluate the criteria before executing the conditional expression. In pseudocode:

result1 = evaluate( criteria1 );

result2 = evaluate( criteria2 );

if( result1 && result2 ) initiate_event;

Note that this is not the same as the following:

if( evaluate( criteria1 ) && evaluate( criteria2 )) initiate_event;

If the evaluation of criteria1 fails for any reason, then the whole expression fails and criteria2 is never evaluated. so if the evaluations must be done independently of each other, then they must be done prior to the conditional expression, storing the results for use in the conditional expression.

What are the application of singly linked list?

A singly-linked list is ideally suited to stacks (last in, first out). The list maintains a link with the head node in the list and each node points to the next node in the list (the last node points to NULL). When a new node is added it is added to the head of the list. Since enqueue and dequeue both occur at the head of the list, processing is always in constant time [O(1)].

With slight modification (maintaining a pointer to the tail node as well as the head), singly-linked lists can also be used for queues (first in first out). Processing remains constant time [O(1)].

However, random access and search are both linear [O(n/2) and O(n) respectively]. While the list can be modified to maintain a sorted list, insert and seek times still average [O(n/2)].

Write overload functions in c plus plus to convert an ascii string to an int and to convert an ascii string to float?

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.

C plus plus program using function median that take three parameters of type double and returns the median of the three?

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 model in sad?

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++.