Scrigroup - Documente si articole


HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

C++ Programming - Answers


+ Font mai mare | - Font mai mic

C++ Programming - Answers

1. What does object orientation in programming means? Explain the meaning of slides 6 and 7 of Lecture 1.

A computer program consists of a group of individual units (objects), which interact with each other. Each object can receive messages, process data given, and send messages to other objects.

Slides 6 and 7 describe the attributes of object-oriented programming. With the help of OOP many people can work on different aspects or individual objects, which at the end can be combined into a one whole program.

2. Name some principles of object orientation.

Composition, classes, inheritance, polymorphism.

1. Are C and C++ languages compatible, i.e. can be source codes of both combined?

Yes, they are compatible. The code of C can be read by C++, but it cannot be the other way around.

2. Write down the programming lines for memory allocation and release for an array of 

integer, double and character variables.

Memory allocation:

cpt_int = (int*)malloc(4);

cpt_double = (double*)malloc(8);

cpt_char = (char*)malloc(1);

Memory release:

free cpt_int;

free cpt_double;

free cpt_char;

3. What are polymorphic functions in C++?

It's a function that can be evaluated and applied to values of different types.

1. Give a definition of C++ class.

It's a set of data and set of functions, which work with this data.

2. What are instances of a class?

They are individual objects of a certain class.

3. What are members of a class?

They are part of the class and can define anything that is within this class. There can be data members or function members.

4. Explain the difference of public, private and protected members.

Public data members and member functions can be accessed by any other function.

Private data members and member functions cannot be accessed by any function that is not a member of that class.

Protected members are available to members of their own class and some related classes.

5. What is the result of this instruction: m_studentA.SetStudentName(name),;?

It's made to set the value of private variable "student_name".

1. What are the standard devices in computer programming?

Standard device for an output is a screen and for an input of data is a keyboard. (As standard input we use often text, and standard output is a kind of stream where the program writes its output data)

2. Which libraries are necessary for I/O operations from/to standard devices?


3. Give an example for output and input of an integer variable.

cout <<my_int_variable;

cin >> any_int_variable;

4. What does the operators << and >> mean?

<< - put to, >> - get from.

5. Which libraries are necessary for I/O operations from/to files?

fstream, iostream and istream

1. Vectors and lists are extensions of C++, they belong to the so called STL. What is necessary to do in order to use them in your source code?

These lines are needed:

#include <vector>

using namespace std;

#include <list>

using namespace std;

2. What are sequences in STL?

It's a list of objects arranged in a linear way, such that the order of the members is well defined.

3. Which data types can be put into vectors and lists?

<vector> - objective:one-dimensional array section

<list> - objective:doubly linked list section

4. Give an example to declare and construct a list and vector of double values.


vector<double> my_vector;


list<double> my_list;

5. What do stack operators in vectors and lists?

The functions push_back and pop_back make a vector behave like a stack. They add and remove elements from vector's end.

6. What can be done with iterators in vectors and lists?

They can be used to navigate the containers.

7. Can we directly access to vector and to list elements?

Vectors can be addressed directly by element number, lists cannot.

8. Can we refer to the next after the next list element?


9. What are differences between vectors and lists? Explain advantages and disadvantages of


The advantage of a vector is fast data access, but they are not as flexible as lists. Deleting and adding of elements within the vector is complicated. On the other hand, list is a sequence used for deletion and insertion of elements. They allow very flexible organization of elements but have relatively slow data access.

1. Explain the meaning of the dialog function DoDataExchange() in Ex.5.

It allows us to link the value of a variable to a control. Immediately after initializing our dialog box, the value of that variable is assigned to its "linked" control.

2. Explain the meaning of the dialog function OnInitDialog() in Ex.5.

This function is called by a program whenever a dialog box is initially instantiated, and usually contains variable declarations and assignments, which will be used by the dialog box during its life cycle.

3. Explain the meaning of the dialog function OnButtonAdd() in Ex.5.

When you hit the button"Add", the function is executed.

4. Explain the meaning of the dialog function OnButtonRemove() in Ex.5

When you hit the button "Remove", the function is executed.

5. Explain the meaning of the dialog function OnSelchangeList() in Ex.5.

After the selection of the element from the list box, this function is executed.

1. Explain the meaning of programming steps 1,2,5: // ??? in the source code

for data base handling below.

2. Explain the meaning of instructions // ??? in the source code for data base

handling below.

void main(int argc, char* argv[]) //Void - there will be no return value. The parameters inside the ( ) are just parameters brought up by the program.

input_file.seekg(0L,ios::beg); // Rewinds the file. The pointer should go back to the beginning.

// Step 2.2:

char buffer[256]; // MAX_LINE// Defines the maximum amount of characters which can be read by the program in one line.

string input_line;

// Read until #STOP, end of data base / A comment




input_line = buffer;



input_line = buffer;



input_line = buffer;



my_list.push_back(m_student); Adds an element in my_list. The  value of the element is given by m_student, which is the address of memory space where the data of each student is stored.


// Step 5: // Student data is being output from the memory to the files

// Step 5.1: // New file output.txt appears

fstream output_file ('output.txt',ios::trunc|ios::out); // An output_file called output.txt is being created, which is a path of the file.

if(!output_file.good()) // Tests the file


output_file.seekg(0L,ios::beg); // Goes back to the beginning of the stream

output_file << 'Example 4: Data Bases and Lists' << endl; // writes 'Example 4: Data Bases and Lists' into the file.

// Step 5.2:

list<CCourseParticipant2003*>::const_iterator p; // Creates a pointer 'p' which points to the items in the list.

p = my_list.begin(); // Asking the pointer p to access the values from the beginning of the list, called my_list.


cout << 'End of program' << endl; // Writes 'End of program on the screen

Politica de confidentialitate | Termeni si conditii de utilizare



Vizualizari: 711
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved