What are words that have special meaning in a programming language called?
Keywords or reserved words.
What are the different mechanism for protecting data from external user of the class in c plus plus?
There is only one mechanism for protecting data in C++: declare the data private. This ensures that only the class and friends of the class have unrestricted access to the data.
Although protected access sounds more appropriate with regards protecting data, this is not the case at all. Protected data has the same restrictions as private data but also exposes the data to derivatives of the class. This means that any user can derive a class from your class and thus gain unrestricted access to the so-called "protected" data.
Although you could declare your class final to prevent users from inheriting from your class, it makes no sense to use protected data in a final class. Although the language would permit such a declaration, the two are mutually exclusive.
Note that, unlike Java, C++ has no 'final' keyword (the C# equivalent is 'sealed'). However, we can make use of existing mechanisms to achieve the same end. Consider the following:
class A;
class B
{
friend class A;
private:
B () {}
};
class A : public virtual B {};
In the above example, class A is final. To understand why, keep in mind that virtual inheritance guarantees that the most-derived class must be able to call the least-derived class constructor first. In this case, the least-derived class B has a private constructor that is only accessible to friend class A. Thus A must always be the most-derived class. In other words, only A can inherit from B and no other class can inherit from A.
Since A is final, it makes no sense to declare any protected members within A as no class can inherit them. Also, it makes no sense to declare protected members in B since A automatically inherits private members of B by virtue of being a friend class and is the only class that can inherit from B in any case.
As a general rule of thumb, protected data should be avoided whenever possible. Data should either be private or public. There is rarely the need for a derived class to inherit data, bearing in mind that this could undermine the encapsulation of your class.
Protected methods are generally OK if you expect your class to be inherited by many classes for which you may not have any control over (an open system), but where those derivatives require access to internal methods that would otherwise be declared private. The only alternative would be to declare those derivatives as friend classes, which is only feasible when you have full control over those derivatives (a closed system). In that case it may prove simpler to use final mechanics instead.
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.
Direct:
int foo ()
{ ... foo (); ... }
Indirect:
int foo ()
{ ... bar (); ... }
int bar ()
{ ... foo (); ... }
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 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.
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.
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.
When a class uses dynamic memory what member function should be provided by class?
the copy constructor
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.
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.
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
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 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.
C plus plus and java are examples of what languages?
They are not examples of languages. They arelanguages.
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;
}
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.
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);
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.