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

What Requirements or skills i should have to be good at C plus programming?

To be a good programmer in C++, your logic making should b strong. You should have a good memory, enough to remember the syntax of codes for c++. And most important of all, you should do regular practice. The more you will practice, more you will master it.

What step is data either written to the file or read from the file?

Insertion is the process of writing data to a file. Extraction is the process of reading data from a file. More generally we use the terms output and inputrespectively. However, the output of one process can often be used as the input for another. Therefore the terms must be applied within the context of the objects being read from or written to.

How do you run c and c plus plus program in edit plus?

EditPlus is a plain-text editor. You use it to edit plain text, just as you would with Windows Notepad, albeit with a lot more features such as syntax highlighting. It cannot be used to run C and C++ programs directly, however you can integrate a 3rd-party compiler. I don't use EditPlus myself, but the documentation should tell you how to go about integrating your compiler.

Types of recursion?

Direct:

int foo ()

{ ... foo (); ... }

Indirect:

int foo ()

{ ... bar (); ... }

int bar ()

{ ... foo (); ... }

What is the difference between redundant and nonredundant structures?

A redundant structure has more structure than is absolutely necessary. This means that, if some part of the structure is damaged or removed, the structure will not necessarily fail or collapse, as another part can bear the load of the damaged or missing piece. A non redundant structure is dependent on every piece of the structure.

Write a function using reference variables as arguments to swap the values of a pair of integers?

#include<iostream>

using namespace std;

void swap(int &i, int &j)

{

int temp = i;

i = j;

j = temp;

}

int main()

{

int i,j;

cin>>i>>j;

cout << i << j << endl;

swap(i,j);

cout << i << j;

return 0;

}

What are the advantages of cout and cin intsead of printf and scanf?

printf and scanf apply to C strings and are not considered type safe for C++ programming. The format specifiers are also quite cryptic. Although they often result in shorter code, it is arguable whether the code is more readable. The C++ standard library is type safe and makes it abundantly clear what is going on.

How do you read in the names and averages from this file?

Adara Starr 94

David Starr 91

Sophia Starr 94

Maria Starr 91

Danielle DeFino 94

Dominic DeFino 98

McKenna DeFino 92

Taylor McIntire 99

Torrie McIntire 91

Emily Garrett 97

Lauren Garrett 92

Marlene Starr 83

Donald DeFino 73

This is the code I have so far:

// David Freed

#include <iostream>

#include <fstream>

using namespace std;

const int MAXNAME = 20;

int main()

{

ifstream inData;

inData.open("grades.txt");

char name[MAXNAME + 1];

float average;

inData.get(name,MAXNAME + 1);

while(inData)

{

cout << "The name of the student is: " << name << endl;

inData >> name;

inData.get();

cout << "His or Her average is: " << average << endl;

inData >> average;

inData.get();

}

return 0;

}

It will give me random averages, and will stop after the first person.

A pseudocode for finding the area of any circle?

Get radius (as parameter)

Calculate area = pi x radius squared

Return area

The above assumes you write a function or method that calculates the area and returns it.

Otherwise:

Ask for radius

Calculate area = pix radius squared

Show area

Four new operators added by c plus plus that aids OOP?

The new operators in C++ (but not in C) are new, delete, compl, and, and_eq, not, not_eq, or, or_eq, xor, xor_eq, bitand and bitor. Of those only the first two can really be said to aid OOP. However, other keywords that specifically aid OOP include class, friend, mutable, private, protected, public and template.

What is inline function in C Can you make inline function recursive or not If make can complier will compile that code?

The inline attribute is a C++ attribute, not a C attribute.

Inline specifies that the function is to be expanded in place at the point of call instead of being called as a function. This means there will be one copy of the function for each call. This costs executable code, but can save execution time because the call setup and return time is avoided. Some functions cannot be inlined, and inline is really only a hint to the compiler.

As far as recursive inlined functions, that depends on the implementation. The Microsoft implementation will not inline recursive functions unless they have a #pragma inline depth(n) line that specifies the maximum recusion depth the function will have. Consult your specific compiler documentation for the inline attribute for your specific implementation details.

What are the symbols used to write comments?

In C++ we use // to begin a comment. A comment can begin anywhere on a line, even after a code statement, and will extend to the end of the line until a newline character is encounter. Multiple lines of comments must each begin with //.

We can also use C-style comments, which begin with /* and end with */. These comments can extend across multiple lines, or can be used to comment out code within a statement.

Why computer known as data processor?

A computer is an electronic device which manipulates or transforms data. it accepts data, stores data, process data according to a set of instructions, and also retrieve the data when required. Hence it is known as a data processor.

What is Code segment in C program?

A code segment, also known as the text segment holds all the executable instructions of the process. The text segment usually starts from the lowest address space of the process memory (leaving behind a small unmapped memory ..not mapped to a physical memory)

--Vivek Purushotham

(vivek.purushotham@gmail.com)

What is an axxess plus key used for?

they are just copies of original keys like car keys house keys etc. look at the number on the key and go to axxess keys under Google and there is a list of numbers telling u what the key is for like 19 is a Chrysler key which means its for a car like like dodge Plymouth or any Chrysler key.

What is Difference between local variable and data members or instance variable?

A data member belongs to an object of a class whereas local variable belongs to its current scope. A local variable is declared within the body of a function and can be used only from the point at which it is declared to the immediately following closing brace. A data member is declared in a class definition, but not in the body of any of the class member functions. Data members are accessible to all member function of the class.

Design stack and queue classes with necessary exception handling?

#include<iostream.h>

#include<process.h>

#define SIZE 10

class Stack

{

private:

int a[SIZE];

int top;

public:

Stack();

void push(int);

int pop();

int isEmpty();

int isFull();

void display();

};

Stack::Stack()

{

top=0;

}

int Stack::isEmpty()

{

return (top==0?1:0);

}

int Stack::isFull()

{

return(top==SIZE?1:0);

}

void Stack::push(int i)

{

try

{

if(isFull())

{

throw "Full";

}

else

{

a[top]=i;

top++;

}

}

catch(char *msg)

{

cout<<msg;

}

}

int Stack::pop()

{

try

{

if(isEmpty())

{

throw "Empty";

}

else

{

return(a[--top]);

}

}

catch(char *msg)

{

cout<<msg;

}

return 0;

}

void Stack::display()

{

if(!isEmpty())

{

for(int i=top-1;i>=0;i--)

cout<<a[i]<<endl;

}

}

int main()

{

Stack s;

int ch=1;

int num;

while(ch!=0)

{

cout<<"1. push"<<endl

<<"2. pop"<<endl

<<"3. display"<<endl

<<"0. Exit"<<endl;

cout<<"Enter ur choice :";

cin>>ch;

switch(ch)

{

case 0: exit(1);

case 1: cout<<"Enter the number to push";

cin>>num;

s.push(num);

break;

case 2: cout<<"a number was popped from the stack"<<endl;

s.pop();

break;

case 3: cout<<"The numbers are"<<endl;

s.display();

break;

default:

cout<<"try again";

}

}

return 0;

}

#include<iostream.h>

#define SIZE 10

class Queue

{

private:

int rear;

int front;

int s[SIZE];

public:

Queue()

{

front=0;

rear=-1;

}

void insert(int);

void del();

int isEmpty();

int isFull();

void display();

};

int Queue::isEmpty()

{

return(front>rear?1:0);

}

int Queue::isFull()

{

return(rear==SIZE?1:0);

}

void Queue::insert(int item)

{

try

{

if(isFull())

{

throw "Full";

}

else

{

rear=rear+1;

s[rear]=item;

}

}

catch(char *msg)

{

cout<<msg;

}

}

void Queue::del()

{

int item;

try

{

if(isEmpty())

{

throw "Empty";

}

else

{

item=s[front];

front=front+1;

cout<<"\n DELETED ELEMENT IS %d\n\n"<<item;

}

}

catch(char *msg)

{

cout<<msg;

}

}

void Queue::display()

{

cout<<"\n";

for(int i=front;i<=rear;i++)

{

cout<<s[i]<<"\t";

}

}

int main()

{

int ch;

Queue q;

int item;

do

{

cout<<"\n\n1.INSERTION \n";

cout<<"2.DELETION \n";

cout<<"3.EXIT \n";

cout<<"\nENTER YOUR CHOICE : ";

cin>>ch;

switch(ch)

{

case 1:

cout<<"\n\t INSERTION \n";

cout<<"\nENTER AN ELEMENT : ";

cin>>item;

q.insert(item);

q.display();

break;

case 2:

cout<<"\n\t DELETION \n";

q.del();

q.display();

break;

}

}while(ch!=3);

return 0;

}

How to program set Cardinality in C plus plus?

The cardinality of a set is simply the number of elements in the set. If the set is represented by an STL sequence container (such as std::array, std::vector, std::list or std::set), then the container's size() member function will return the cardinality.

For example:

std::vector<int> set {2,3,5,7,11,13};

size_t cardinality = set.size();

assert (cardinality == 6);

What are the merits and demerits of using friend function?

disadvantage of friend functions is that they require an extra line

of code when you want dynamic binding. To get the effect of a virtual friend,

the friend function should call a hidden (usually protected:) virtual[20]

member function.

What is housekeeping in programming?

'Good housekeeping' in C++ (C Plus Plus) programming could refer to the tidiness of one's coding.

Code that is messy and without structure can become difficult to read, and if passed to another programmer, difficult to understand. If you comment code, structure it consistently and with a constant style, your code will be clean enough so that any programmer could pick it up and understand it.

How do you pause the screen at visual studio 2008?

When debugging console applications using F5, the default behaviour is to close the console window as soon as the program exits. You can prevent this by placing a breakpoint on the return statement(s) in your main() function.

Alternatively, you can run the program outside the debugger with CTRL+F5. This is the same as running the program from the command line and the console window will remain open when the program exits.

What are the disadvantage of UML?

Developing/coding/modeling anything while satisfying any specific standards will usually decrease the technical performance (efficiency) of your end product (software). Standards (like UML standards) are there to make creating the end product a more rapid process, and to make it more manageable to work with other people / reuse existing software. A 'capable programmer/developer' can almost always create end products that perform better by explicitly creating the program for its purpose, disregarding standard routines.

However, you almost always DO want to follow standards (not just UML), because the performance loss is negligible for most products.