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

Is machine language very easy to read and understand?

Lets put it this way- there are probably about 6 people in the world who can understand machine language. It is all 1010001010100101001100101

Which os is build in Java compiler?

Java compiler available on multiple platforms, the class files it generates are platform-independent.

How do you write a program to make asterisk isosceles triangle using for loop in c plus plus?

*

**

***

****

simply use dis...

{

int x,y;

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

{

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

printf("*");

printf("\n");

}

}

Counting the occurrence of duplicate nodes in C plus plus?

It depends on whether the nodes are in a list, a binary tree, a heap, or some other structure. If the nodes are in an unsorted list, then the simplest solution would be to build a frequency table (requiring a single traversal of the list), and then list all the table elements that have a frequency greater than 1. If the list is sorted, then duplicate nodes will always be found side-by-side, thus you can quickly enumerate them without the need of a frequency table unless you wished to store the results for further analysis.

Similar procedures can be done with other structures. For instance, sorted binary trees in ascending order will have equal nodes to the right of a parent node (greater than or equal to). Regardless, you must traverse the entire structure in order to determine the frequency of each node, and thus the frequency of duplicate nodes.

Why do are symbols defined in a Solaris CC library listed as undefined by ld?

You are probably trying to build a dynamic library. If so, do not use ld, use CC -g instead.

What is the Syntax of remainder operator in c language?

% = Shift + 5

Example:

printf ("7%%3=%d\n", 7%3);

result: 7%3=1

one more thing this operator works only with integer type numbers not floating numbers.

How do you write Multithreaded applications using C plus plus?

Use std::packaged_task (preferably) or std::thread to start a new thread. Use std::future (preferred), std::mutex or std::atomic to share information between threads.

How to convert c to c for cuda?

Cuda is c, just using a special library. It is almost identical to standard C, except for the additional options, libraries, and thread handling. Nvidia has a good tutorial. There is a huge difference though. Cuda is basically a large number of slow, memory limited threads, that combined can be much faster than a cpu. Often you will need to rewrite the math algorithm to be highly parallel, and use little memory. AKA, this is going to require some reading and research, it is not as trivial as you would like in many cases.

How do you write code C plus plus program to compute nett salary for 5 employees given that the allowance is 20 percent of basic pay and income tax is 30 percent of the gross salary?

#include<iostream>

#include<string>

#include<sstream>

int main()

{

for (size_t employee=1; employee<=5; ++employee)

{

bool ok = false;

while (!ok)

{

std::string input;

std::cout << "Employee #" << employee << std::endl;

std::cout << "Enter basic pay: ";

std::getline (std::cin, input);

std::stringstream ss;

ss << input;

double pay;

if (ss >> pay)

{

double allowance = pay * 20 / 100;

double tax = (pay-allowance) * 30 / 100;

double nett = pay - tax;

std::cout << "Basic pay:\t" << pay << std::endl;

std::cout << "Allowance:\t" << allowance << std::endl;

std::cout << "Tax:\t\t" << tax << std::endl;

std::cout << "Nett:\t\t" << nett << std::endl;

ok = true;

}

else

{

std::cout << "Bad input\n";

}

}

std::cout << std::endl;

}

}

What is seekg?

In C++, seekg is a method/function of the standard fstream library (fstream::seekg()) which allows you to position the 'get' pointer to an arbitrary position within the stream.

What computer language java or C plus plus should you use to design an app for the ipod or should i use a software?

You would use neither Java nor C++, you would use Objective-C, in conjunction with the Apple iPod API (iPod Library Access).

What is client server approach of c plus plus?

Client/server programs typically employ multi-threading where the primary thread handles the server side of things while one or more threads handle the client side.

How do you create an AI in c plus plus programming language?

Artificial intelligence is such a vast area of study it is difficult to give a precise answer. Assuming you already know how to program in C++ you should probably start by reading "Artificial Intelligence: A Modern Approach" and apply that knowledge to your programming. If you have a more specific AI in mind, look for a book that deals with that specific field. However, one thing I can guarantee is that implementing AI is not easy and attempting it in C++ just makes it that much harder for yourself. Although there are AI libraries that'll make things a little easier, I would suggest you start with a higher level language, such as Lisp, which is much better suited to AI applications.

C program to multiply two complex no?

/*C++ program to multiply two complex numbers using * operator overloading*/

#include<iostream.h>

#include<conio.h>

class complex

{

float x,y;

public:

complex() {}

complex(float real,float img)

{

x=real; y=img;

}

complex operator*(complex);

void display()

{

cout<<x<<" + "<<y<<"i"<<endl;

}

};

complex complex::operator*(complex e)

{

complex temp;

temp.x=x*e.x+y*e.y*(-1);

temp.y=x*e.y+y*e.x;

return(temp);

}

void main()

{

clrscr();

complex c1(5,3),c2(3,2),c3=c1*c2;

c1.display();

c2.display();

cout<<"Multiplication"<<endl;

c3.display();

getch();

}

OUTPUT:

5 + 3i

3 + 2i

Multiplication

9 + 19i

Algorithm for finding the factorial using iterative function?

// returns n!

int fact(int n) {

int f_n = 1;

for(int i = n; i > 1; --i) {

f_n *= n;

}

return f_n;

}

What is the function of immediate access store?

· This holds the data and programs needed at that instant by the Control Unit. The CPU reads data and programs kept on the hard disk and stores them temporarily in the IAS's memory. This is because the hard disk is too slow to be able to run applications directly.

How do you create menu in c plus plus?

#include<iostream>

#include<conio.h> // for _getch()

void action1_1_1() { std::cout << "Performing action 1.1.1\n\n"; }

void action1_1_2() { std::cout << "Performing action 1.1.2\n\n"; }

void action1_1_3() { std::cout << "Performing action 1.1.3\n\n"; }

void action1_2_1() { std::cout << "Performing action 1.2.1\n\n"; }

void action1_2_2() { std::cout << "Performing action 1.2.2\n\n"; }

void action1_2_3() { std::cout << "Performing action 1.2.3\n\n"; }

void action1_3_1() { std::cout << "Performing action 1.3.1\n\n"; }

void action1_3_2() { std::cout << "Performing action 1.3.2\n\n"; }

void action1_3_3() { std::cout << "Performing action 1.3.3\n\n"; }

void action2_1_1() { std::cout << "Performing action 2.1.1\n\n"; }

void action2_1_2() { std::cout << "Performing action 2.1.2\n\n"; }

void action2_1_3() { std::cout << "Performing action 2.1.3\n\n"; }

void action2_2_1() { std::cout << "Performing action 2.2.1\n\n"; }

void action2_2_2() { std::cout << "Performing action 2.2.2\n\n"; }

void action2_2_3() { std::cout << "Performing action 2.2.3\n\n"; }

void action2_3_1() { std::cout << "Performing action 2.3.1\n\n"; }

void action2_3_2() { std::cout << "Performing action 2.3.2\n\n"; }

void action2_3_3() { std::cout << "Performing action 2.3.3\n\n"; }

void action3_1_1() { std::cout << "Performing action 3.1.1\n\n"; }

void action3_1_2() { std::cout << "Performing action 3.1.2\n\n"; }

void action3_1_3() { std::cout << "Performing action 3.1.3\n\n"; }

void action3_2_1() { std::cout << "Performing action 3.2.1\n\n"; }

void action3_2_2() { std::cout << "Performing action 3.2.2\n\n"; }

void action3_2_3() { std::cout << "Performing action 3.2.3\n\n"; }

void action3_3_1() { std::cout << "Performing action 3.3.1\n\n"; }

void action3_3_2() { std::cout << "Performing action 3.3.2\n\n"; }

void action3_3_3() { std::cout << "Performing action 3.3.3\n\n"; }

void submenu1_1()

{

while (true)

{

std::cout

<< "SUBMENU 1.1\n===========\n\n"

<< "1 - action 1.1.1\n"

<< "2 - action 1.1.2\n"

<< "3 - action 1.1.3\n"

<< "X - exit to submenu 1\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action1_1_1(); break;

case '2': action1_1_2(); break;

case '3': action1_1_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu1_2()

{

while (true)

{

std::cout

<< "SUBMENU 1.2\n===========\n\n"

<< "1 - action 1.2.1\n"

<< "2 - action 1.2.2\n"

<< "3 - action 1.2.3\n"

<< "X - exit to submenu 1\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action1_2_1(); break;

case '2': action1_2_2(); break;

case '3': action1_2_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu1_3()

{

while (true)

{

std::cout

<< "SUBMENU 1.3\n===========\n\n"

<< "1 - action 1.3.1\n"

<< "2 - action 1.3.2\n"

<< "3 - action 1.3.3\n"

<< "X - exit to submenu 1\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action1_3_1(); break;

case '2': action1_3_2(); break;

case '3': action1_3_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu2_1()

{

while (true)

{

std::cout

<< "SUBMENU 2.1\n===========\n\n"

<< "1 - action 2.1.1\n"

<< "2 - action 2.1.2\n"

<< "3 - action 2.1.3\n"

<< "X - exit to submenu 2\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action2_1_1(); break;

case '2': action2_1_2(); break;

case '3': action2_1_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu2_2()

{

while (true)

{

std::cout

<< "SUBMENU 2.2\n===========\n\n"

<< "1 - action 2.2.1\n"

<< "2 - action 2.2.2\n"

<< "3 - action 2.2.3\n"

<< "X - exit to submenu 2\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action2_2_1(); break;

case '2': action2_2_2(); break;

case '3': action2_2_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu2_3()

{

while (true)

{

std::cout

<< "SUBMENU 2.3\n===========\n\n"

<< "1 - action 2.3.1\n"

<< "2 - action 2.3.2\n"

<< "3 - action 2.3.3\n"

<< "X - exit to submenu 2\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action2_3_1(); break;

case '2': action2_3_2(); break;

case '3': action2_3_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu3_1()

{

while (true)

{

std::cout

<< "SUBMENU 3.1\n===========\n\n"

<< "1 - action 3.1.1\n"

<< "2 - action 3.1.2\n"

<< "3 - action 3.1.3\n"

<< "X - exit to submenu 3\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action3_1_1(); break;

case '2': action3_1_2(); break;

case '3': action3_1_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu3_2()

{

while (true)

{

std::cout

<< "SUBMENU 3.2\n===========\n\n"

<< "1 - action 3.2.1\n"

<< "2 - action 3.2.2\n"

<< "3 - action 3.2.3\n"

<< "X - exit to submenu 3\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action3_2_1(); break;

case '2': action3_2_2(); break;

case '3': action3_2_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu3_3()

{

while (true)

{

std::cout

<< "SUBMENU 3.3\n===========\n\n"

<< "1 - action 3.3.1\n"

<< "2 - action 3.3.2\n"

<< "3 - action 3.3.3\n"

<< "X - exit to submenu 3\n\n";

int i = _getch();

switch ((char) i)

{

case '1': action3_3_1(); break;

case '2': action3_3_2(); break;

case '3': action3_3_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu1()

{

while (true)

{

std::cout

<< "SUBMENU 1\n=========\n\n"

<< "1 - sub-menu 1.1\n"

<< "2 - sub-menu 1.2\n"

<< "3 - sub-menu 1.3\n"

<< "X - exit to main menu\n\n";

int i = _getch();

switch ((char) i)

{

case '1': submenu1_1(); break;

case '2': submenu1_2(); break;

case '3': submenu1_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu2()

{

while (true)

{

std::cout

<< "SUBMENU 2\n=========\n\n"

<< "1 - sub-menu 2.1\n"

<< "2 - sub-menu 2.2\n"

<< "3 - sub-menu 2.3\n"

<< "X - exit to main menu\n\n";

int i = _getch();

switch ((char) i)

{

case '1': submenu2_1(); break;

case '2': submenu2_2(); break;

case '3': submenu2_3(); break;

case 'X':

case 'x': return;

}

}

}

void submenu3()

{

while (true)

{

std::cout

<< "SUBMENU 3\n=========\n\n"

<< "1 - sub-menu 3.1\n"

<< "2 - sub-menu 3.2\n"

<< "3 - sub-menu 3.3\n"

<< "X - exit to main menu\n\n";

int i = _getch();

switch ((char) i)

{

case '1': submenu3_1(); break;

case '2': submenu3_2(); break;

case '3': submenu3_3(); break;

case 'X':

case 'x': return;

}

}

}

int main()

{

while (true)

{

std::cout

<< "MAIN MENU\n=========\n\n"

<< "1 - sub-menu 1\n"

<< "2 - sub-menu 2\n"

<< "3 - sub-menu 3\n"

<< "X - exit program\n\n";

int i = _getch();

switch ((char) i)

{

case '1': submenu1(); break;

case '2': submenu2(); break;

case '3': submenu3(); break;

case 'X':

case 'x': return 0;

}

}

}

Write a C plus plus program to move a node to nth position in forward?

#include<iostream>

#include<forward_list>

void print (std::forward_list<unsigned>& list)

{

for (std::forward_list<unsigned>::iterator i=list.begin(); i!=list.end(); ++i)

std::cout << *i << '\t';

std::cout << std::endl;

}

bool insert (std::forward_list<unsigned>& list, unsigned value, unsigned position)

{

// there is no 0th position

if (position list.end())

return false;

// i is the nth-1 node

list.insert_after (i, value);

return true;

}

bool move (std::forward_list<unsigned>& list, unsigned value, unsigned position)

{

list.remove (value);

return (insert (list, value, position));

}

int main()

{

// initialise a forward list with 9 unique values 1, 2, 3, ..., 8, 9

std::forward_list<unsigned> list;

for (unsigned i=1; i<=10; ++i)

insert (list, i, i);

std::cout << "initial list\n" << std::endl;

print (list );

// insert the value 11 at the 6th position in the list

insert (list, 11 , 6);

std::cout << "\nafter inserting the value 11 at position 6\n" << std::endl;

print (list);

// move the value 11 to position 11 in the list

move (list, 11, 11);

std::cout << "\nafter moving the value 11 to position 11\n" << std::endl;

print (list);

}

Why you are mark a class protected for inheritance?

Public, Private and Protected "keywards/ access modifiers" are used similarly as they are with variables. Protected variables, methods or class CAN ONLY be used by an inherited class.

How do you install Turbo C plus plus on Windows 7?

You can use a software called DOSbox

Another Answer:

Turbo C++ was discontinued in 2009 by Embarcadero Technologies. While you might be able to get it to run in Windows 7 using compatibility mode, it would be better to upgrade to C++Builder.

You can use DOSBox to install Turbo C in Windows 7. Or Turbo C Simulator which install Turbo C in Windows 7 in a single click.

What are the 4 nitrogen bases and their function?

The four nitrogen bases are Adenine, Thymine, Cytosine, and Guanine. Their job is composing a code for DNA to shape the physical characteristics of most living things.