A game company's interview questions

xiaoxiao2021-03-06  44

Note: All topic answers please provide the answer idea, otherwise it will be deemed to have not answered.

1. There are 1,000 apples, 10 boxes, and ask how many apples should be placed in each box to make the user to buy an apple between any 1 to 1000, you can give him (the whole box is the whole box " Sell, can not remove the box packaging). 2. Please read the following information: a material: CArraytemplate class CArray: public CObjectParameters:. TYPETemplate parameter specifying the type of objects stored in the array TYPE is a parameter that is returned by CArray.ARG_TYPETemplate parameter Specifying the argument type used to access objects stored in the array.

OFTEN A Reference to Type. Arg_type is a parameter That is passed to carray.

Remarks: The Carray Class Supports Arrays That Are Are Similarly Shrrays, But Can Dynamically Shrink and Grow As Necessary.

Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null. Int CArray :: Add (ARG_TYPE newElement); Return Value: The index of the added element.Parameters: ARG_TYPETemplate parameter specifying the type of arguments referencing elements in this array.newElementThe element to be added to this array tYPE & CArray :: operator [] (. int nIndex); Parameters:. TYPETemplate parameter specifying the type of elements in this array.nIndexIndex of the element to be accessed.Remarks: Returns the array reference of element at the specified index 1) two materials: CListtemplate class CList: public CObjectParameters: TYPEType of object stored in the list.ARG_TYPEType used to reference objects stored in the list Can be a reference.Remarks:. The CList class supports ordered lists of nonunique objects accessible .. Sequentially or by value CList lists behave like doubly-linked lists void CList :: AddTail (ARG_TYPE newElement); Parameters: ARG_TYPETemplate parameter specifying the type of the list element (can be a reference) .newElementThe element to be added to this list .Remarks: Adds a new element or list of elements to the tail of this list. The list can be empty before the operation.

2) three materials: reallocreallocReallocate memory blocks.void * realloc (void * memblock, size_t size); Return Value: The return value points to a storage space that is guaranteed to be suitably aligned for storage of any type of object To get a. pointer to a type other than void, use a type cast on the return value.Remarks:. The size argument gives the new size of the block, in bytes The contents of the block are unchanged up to the shorter of the new and old sizes , although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument. 3) Please indicate below code problems may occur CList g_ValueList; CArray g_ValuePool; void AddNewValue (const VARIANT & newValue) {g_ValueList.AddTail (& g_ValuePool [g_ValuePool.Add (newValue)]);} 3. There is a symbolic integer array, the size is 10, the initial value is random, but between [0, 99]. Write a filter with the C language, and the data within the array is not equal. Note: 1. If there is equal data in the array, you can make an offset of 1 or minus 1 to do not wait until it is. 2. The data within the array can only be between [0, 99]. 3. Keep the data position within the array constant, that is, the corresponding subscript is unchanged.

4. Write the following functions as required. Function: Moving # characters in the given buffer to string tail function name: ChangeTotail entry parameter: PSZ pointing to the pointer of the buffer, the nsize buffer length exit: PSZ refers to # characters in the buffer in the buffer to the buffer Tissue return value: In the first # of the exit buffer, if there is no # character in the buffer, return -1 description: If you pass # w # w # w #, 10 should be converted to Wwwww ##### and return value is 5INT ChangeTotAil (Byte * PSZ, uint nsize) {// Todo: Add your code here.

5. Read the following procedure and correct it. (40 minutes)//-------------------------------------------- ---------------------- Class Ccelsius {public: ccelsius () {m_nc = 0;} ~ ccelsius () {}

Short Tofahrenheit () {RETURN M_NC * 9/5 32;} void setc (short ncelsius) {m_nc = ncelsius;} short getc () {returnrn m_nc;}

Protected: short m_nc;}; class cfahrenheit {public: cfahrenheit () {m_nf = 0;} ~ cfahrenheit () {}

Short toolsius () {RETURN (M_NF - 32) * 5/9; void setf (short nfahrenheit) {m_nf = nfahrenheit;} short getf () {return m_nf;}

PROTECTED: Short M_NF;};

Class CTemperature: Public Ccelsius, Public Cfahrenheit {public: ctemperature (); ~ ctemperature ();

Bool CreateLevel (Uint Nsize); Void ReleaseElevel (); Uint Getlevel (Int ncelsius);

Protected: uint m_nsize; short * m_plevel;};

/ / -------------------------------------------------------------------------------------------- ------------------

CTemperature :: ctemperature () {m_nsize = 0; m_plevel = null;

CTemperature :: ~ ctemperature () {transleaseclite ();

Bool ctemperature :: CreateLevel (uint nsize) {assert (m_plevel == null); if (m_plevel) returnaf false;

M_PLEVEL = New Short [nsize]; if (m_prlevel == null) Return False;

For (uint i = 0; i

m_nsize = nsize; return true;}

Void ctemperature :: ReleaseEvel () {if (m_plevel) {delete [] m_plevel; m_nsize = 0; m_prlevel = null;}}

Uint Ctemperature :: getLet NT {assert (m_plevel);

For (uint nlevel = 0; NLEVEL nt) Break;} return nlevel;}

Void OUTC (CCELSIUS * PC) {IF (PC) Printf ("" Celsius% D degree is equal to Hua Maximum D degree / N ", PC-> Getc (), PC-> Tofahrenheit ());}

Void outf (cfahrenheit * pf) {if (pf) Printf ("Fahrenholi D degree is equal to Celsius% D degree / N", pf-> getf (), pf-> tocelsius ());}

Void Outl (CTEMPERATURE * PT) {if (pt) {printf ("" Celsius% D degree level is:% D / N ", Pt-> getc (), Pt-> getlevel (Pt-> getc ())))) PRINTF ("Hua's% D degree is:% D / N", PT-> getf (), Pt-> Getlevel (Pt-> getf ());}}

void main () {CTemperature * pTemperature = new CTemperature; if (pTemperature == NULL) return; CCelsius * pCelsius = (CCelsius *) pTemperature; pCelsius-> SetC (100); OutC (pCelsius); CFahrenheit * pFahrenheit = (CFahrenheit *) pCelsius; pFahrenheit-> setF (400); OutF (pFahrenheit); pTemperature-> CreateLevel (3); OutL (pTemperature); CTemperature * pTempOther = new CTemperature; if (pTempOther == NULL) return; * pTempOther = * Ptemperature; delete pfahrenheit; uTL (PTEMPOTHER); DELETE PTEMPOTHER;} 6. C program design 1) Write the following procedure: #include class base {public: base () {cout << "Base () "<< Endl;} Base (const base & itbase) {cout <<" Base (const base & itbase) << endl;} ~ base () {cout << "~ base ()" << endl;} void Open () {Onopen ();} private: Virtual void onopen () = 0;

Class Derived: public base {public: derived () {cout << "Derived ()" << endl;} Derived (const derived) {cout << "Derived & THederived" << endl;} ~ derived () {Cout << "~ derived ()" << Endl;} private: Virtual void onopen () {// This may throw anomalous}}}}}}}}}};

Int main () {base * PBase = :: createInstance (); if (pBase) {PBase-> open (); delete pBase;} Return 0;

2) Is there any problem with the implementation of class base and class Derived? If so, how to modify it?

3) Description 1) The design purpose and significance of the Open function and the ONOpen function of the class base.

4) Use STL technology to modify the code in the main () function, making it an unusual security.

转载请注明原文地址:https://www.9cbs.com/read-83147.html

New Post(0)