.


:




:

































 

 

 

 


MS Windows MS- DOS

 

 

 

( 1)

 

 

2010


 

681.3 ´5(07.07)

 

: ..

 

( 1). : - ,

2000. 30 .

 

1-11 .

.

 

.: 8 .

 

.. , . . , .

 

 


. 1-11.

, , 1-11.

1. , , , , , .

2. .

3. , " " .

4. .

 

1

++

1. : ++.

 

2.1 .

2.2 .

2.3 .

 

.

3.1 1, .

// 1

#include "stdafx.h"

#include <iostream>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

cout<<"\nsizeof(int) = " << sizeof(int);

cout<<"\nsizeof(short) = " << sizeof(short);

cout<<"\nsizeof(long) = " << sizeof(long);

cout<<"\nsizeof(float) = " << sizeof(float);

cout<<"\nsizeof(double) = " << sizeof(double);

cout<<"\nsizeof(char) = " << sizeof(char);

cout<<"\nsizeof('a') = " << sizeof('a');

cout<<"\nsizeof(1) = " << sizeof(1);

cout<<"\nsizeof(1L) = " << sizeof(1L);

cout<<"\nsizeof(1U) = " << sizeof(1U);

cout<<"\nsizeof(1.) = " << sizeof(1.);

cout<<"\nsizeof(1.F) = " << sizeof(1.F);

cout<<"\nsizeof(1.L) = " << sizeof(1.L);

cout<< "\n (4<<2) = " <<(4<<2);

cout<<"\n (5>>1) = " << (5>>1);

cout<<"\n (6&5) = " << (6&5);

cout<<"\n (6|5) = " << (6|5);

cout<<"\n (3<5) = " << (3<5);

cout<<"\n (3>5) = " << (3>5);

cout<<"\n (3==5) = " << (3==5);

cout<<"\n (3!=5) = " << (3!=5);

cout<<"\n Press key to continue";

getchar();

 

 

cout<<"\n (3!=5 || 3==5) = " << (3!=5 || 3==5);

cout<<"\n (3+4>5 && 3+5 > 4 && 4+5>3) =" << (3+4>5 && 3+5 > 4 && 4+5>3);

 

int k;

cout<<"\n (k=35/4) = " << (k=35/4); //

cout<<"\n (k/=1+2+2) = " << (k/=1+2+2);

cout<<"\n (k*=5-2) = " << (k*=5-2);

cout<<"\n (k%=3+2) = " << (k%=3+2);

cout<<"\n (k+=21/3) = " << (k+=21/3);

cout<<"\n (k-=6-6/2) = " << (k-=6-6/2);

cout<<"\n (k<<=2) = " << (k<<=2);

cout<<"\n (k>>=6-5) = " << (k>>=6-5);

cout<<"\n (k&=9+4) = " << (k&=9+4);

cout<<"\n (k|=8-2) = " << (k|=8-2);

getchar();

}

3.2 1.

3.3 .

3.4 .

3.5 .

 

.

4.1 .

4.2 1 .

4.3 .

 

.

5.1 , , ?

5.2 , , , . ++. .

5.3 , , .

5.4 .

5.5 , ++?

5.6 , . .

5.7 & &&, | ||.

5.8 %, *=, +=, /=.

5.9 8 (3+4>5 && 3+5 > 4 && 4+5>3). , 8 . (3+4>(5 && 3)+5 > 4 && 4+5>3). .

5.10 .

5.11 , //, 35 , .

 

2

++

, ++.

 

1. : ++, , .

 

2.1 . .

2.2 . .

 

.

3.1 1 2.

// 1 .

#include "stdafx.h"

#include <iostream>

#include <math.h>

using namespace std;

 

void main (){

long k = 123456789;

float g = (float)k;

cout<<"\n\n k = "<<k;

cout<<"\n g= "<<g;

k = (long)g;

cout<<"\n k = "<<k; //

g = (float) 2.222222e+2;

int m = (int)g;

cout<<"\n\n g = " <<g;

cout<<"\n m = "<<m;

g = (float)m;

cout<<"\n g = "<<g;

int a=1, b = 2;

double c = 1;

c = a/b*c+ a*c/b;

cout<<"\n c = "<<c; //

cout<<"\n 1/2*exp(1) = "<<1/2*exp(1.); //

getchar();

}

 

// 2 ,

#include "stdafx.h"

#include <iostream>

using namespace std;

 

extern double k; // k

void main (){

double a = 2, b = 3;//, a b.

k = 1.3*k/((a+b)*(a-b));

cout<< "\n k = "<<k;

getchar();

}

double k=1; // k

3.2 1 2.

3.3 2 , (+), (-), (*), (/). . k = 1.3*k/((a+b)*(a-b)); .

// , +:

#include "stdafx.h"

#include <iostream>

using namespace std;

 

double sum(double a, double b); // sum()

extern double k;

void main (){

k = 1;

double a = 2, b = 3;

k = 1.3*k/(sum(a,b)*(a-b)); // sum()

cout<< "\n k = "<<k;

getchar();

}

double sum(double a, double b){ // sum()

return a+b;

}

double k;

3.4 .

3.5 3, t = 0, 0.1 0.4.

3.6 .

3.7 .

 

4.1 . .

4.2 1.

4.3 2, , -, *, /.

4.4 3.

 

5.1 , ( )? , ?

5.2 ? ?

5.3 , . ?

5.4 ? ? ?

5.5 ? .

5.6 : , , , , , .

5.7 , , ? . ?

5.8 . 1.

5.9 ? , . , ?

5.10 , , , , .

 

 

3

++. ++

1. : ++. .

 

2.1 ++ [2].

2.2 1

2.3 , .

 

3.1 1, , . 1

. 1

// 1

#include "stdafx.h"

#include <iostream>

using namespace std;

 

void main (){

int N;

cout<<"\n Input N = ";

cin>>N;

double a = 1, b = 6;

double h = (b-a)/N, t = a, S1 = 0,S2 = 0, y=0;

//

for(int i = 0; i < N; i++, t+=h){

if(t>=a && t<=3) {y = 1.5*t-1.5; S1 += h*y; }

if(t>=3 && t<=b) y = -1*t+6, S1 += h*y;

}

double y_last = 0;

t = a, y=0;

//

for(int i = 0; i < N+1; i++, t+=h){

if(t>=a && t<=3) y = 1.5*t-1.5, S2 += h*(y+y_last)/2;

if(t>3 && t<=b) y = -1*t+6, S2 += h*(y+y_last)/2;

y_last = y;

}

cout<<"\n S1= "<<S1;

cout<<"\n S2= "<<S2;

getchar();

getchar();

}

 

3.2 .

3.3 2

 

// 2 ( )

#include "stdafx.h"

#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <iostream>

using namespace std;

 

const int size = 100;

float fData[size];

void BubbleSort(float fArrayToSort[],int iNumberOfElements);

void main()

{

srand(1); //

int index;

//

for (index = 0; index < size; ++index)

fData[index] = rand() % 100;

BubbleSort(fData, size);

for (index = 0; index < size; index++)

cout<<"\n fData["<<index<< "] = "<<fData[index];

printf("\n");

getchar();

}

//

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

void BubbleSort(float fArrayToSort[],float iNumberOfElements)//

{

int i,j;

float fTemp;

for (i = 0; 1 < iNumberOfElements - 1; i++) //

for (j = iNumberOfElements - 1; j > i; j--){

if (fArrayToSort[j] < fArrayToSort[j-1]){

// fArrayToSort[j] fArrayToSort[j-1];

fTemp = fArrayToSort[j];

fArrayToSort[j] = fArrayToSort[j-1];

fArrayToSort[j-1] = fTemp;

}

}

}

 

 

3.4 Help, , 1 2.

3.5 . 2 , , .

3.6 .

 

4.1 . .

4.2 1 2.

4.3 , 1, .

 

5.1 , n, 3 .

5.2 , .

5.3 , , .

5.4 , .

5.5 a0x2+a1x+a2=0 ( a0, a1, a2 ).

5.6 y(x) = a0x2+a1x+a2 ( a0, a1, a2 ).

5.7 f(t) = 4psin(2pt)+ 4p/3sin(6pt) +4p/5sin(10pt).

5.8 , .

5.9 , . .

5.10 . .

5.11 . .

5.12 . .

5.13 , .

 

 

4

MS Windows MS- DOS

 

1. : , , , , .

 

1. , " !" MS-DOS MS Windows .

2. '' MS-DOS MS Windows (unsigned char p = 'A'; p= p+64;), , ''?

 

3.1 1 2

// 1

// /++->-> ; _CRT_SECURE_NO_WARNINGS

#include "stdafx.h"

#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <fcntl.h>

#include <sys\stat.h>

#include <io.h>

using namespace std;

int main(void){

setlocale(LC_ALL, "rus");

int handle;

char msg[] = "Hello world";

if ((handle = _open("C:\\RXX\\TEST.txt", O_CREAT | O_TEXT| O_RDWR, S_IWRITE | S_IREAD)) == -1) {

perror("Error:");

getchar();

return 1;

}

_write(handle, msg, strlen(msg)); //msg == &msg[0]

_close(handle);

cout<<"\n Hello world - write to file";

getchar();

return 0;

}

// 2

#include "stdafx.h"

#include <stdio.h>

#include <io.h>

#include <malloc.h>

#include <fcntl.h>

#include <process.h>

#include <sys\stat.h>

#include <iostream>

using namespace std;

int main(void){

 

int handle, bytes;

if ((handle =_open("C:\\RXX\\TEST.txt", O_RDWR | O_BINARY, S_IWRITE | S_IREAD)) == -1){

printf("Error Opening File\n");

getchar();

exit(1);

}

long longFile = _lseek(handle,0,SEEK_END);

_lseek(handle,0,SEEK_SET);

unsigned char* buf = (unsigned char*)malloc(longFile+1);

if ((bytes = _read(handle, buf, longFile)) == -1) {

printf("Read Failed.\n");

free(buf);

getchar();

exit(1);

}

else {

printf("Read: %d bytes read.\n", bytes);

// buf[longFile]='\0';

cout<<buf;

}

free(buf);

getchar();

return 0;

}

3.2 1 2. ( 1 Test.txt "Hello world". 2 Test.txt .)

3.3 2 , , .. "Hello world", "dlrow olleH"

3.4 , MS-DOS MS Windows. ( [1] . 488-493).

3.5 .

3.6 .

 

4.1 . .

4.2 , .

 

5.1 ? ? .

5.2 s, int b; int& s = b;? s.

5.3 lseek() .

5.4 double Ar[3][4][5], Ar, Ar[2], Ar[1][3], ***Ar, *(*(*(Ar+1)+2)+1).

5.5 * &. .

5.6 , , .

5.7 , .

5.8 , .

5.9 , .

5.10 , , , () ().

5.11 , .

5.12 , sym = F(sym), F() - (, =^0xFF).

 

5

++

 

1. : . .

 

2.1 , . , . , .

#include <iostream.h>

int f1(int b) {b=b+1; return b;}//

int& f2(int& b) {b=b+1; return b;}

int* f3(int* b) { *b=*b+1;return b;}

void main(){

int a =1; cout<<"\n a = "<<a;

cout<<"\n f1(a) = "<<f1(a); cout<<"\t a = "<<a; // f1(a) = 2 a = 1;

cout<<"\n f2(a) = "<<f2(a); cout<<"\t a = "<<a;// f2(a) = 2 a = 2;

cout<<"\n *f3(&a) = "<<*f3(&a); cout<<"\t a = "<<a; // *f3(&a) = 3 a = 3;

}

 

2.2 , :

double factorial(unsigned value)

{

unsigned i = 1;

double result = 1;

for (; i <= value; i++) result *= i;

return result;

}

2.3. :

1. F(x) = sin(x)+4*cos(2*x) o 0 π/4

2. F(x) = 7*x2+5*x+3 3 6

3. F(x) = -7*x3+3*cos(3*x) x 0 π/2

4. F(x) = 5*cos(3*x)-12*sin(3*x) π/4 π

5. F(x) = 0.01*(1-x2) 0.01 0.5

6. F(x) = 1/(1-x) 2 5

7. F(x) = sin(x)+(x2+4) - π/4 π/4

8. F(x) = 7*x3-5*x+7 1 2

9. F(x) = sin(x)+cos(4x) 0 π

10. F(x) = 0.1*x2(1-x3) -3 3

 

3.1 , , .

#include "stdafx.h"

# include <stdio.h>

# include <stdlib.h>

#include <time.h>

# define DIMENSION 5000

void QuickSort(int* array, int First, int Last)

{

int Temp, LowerBoundary, UpperBoundary, Separator;

LowerBoundary = First;

UpperBoundary = Last;

Separator = array[(First + Last) / 2];

do

{

while (array[LowerBoundary] < Separator) LowerBoundary++;

while (array[UpperBoundary] > Separator) UpperBoundary--;

if (LowerBoundary <= UpperBoundary)

{

Temp = array[LowerBoundary];

array[LowerBoundary++] = array[UpperBoundary];

array[UpperBoundary--] = Temp;

}

} while (LowerBoundary <= UpperBoundary);

if (First < UpperBoundary) QuickSort(array, First, UpperBoundary);

if (LowerBoundary < Last) QuickSort(array, LowerBoundary, Last);

}

void main()

{

time_t ftime, stime;

int i = 0;

int* ar = (int*) malloc(sizeof(int)*DIMENSION);

for (; i < DIMENSION; ar[i++] = rand()%1000);

time(&ftime); //

QuickSort(ar, 0, DIMENSION -1);

time(&stime); //

printf("\n\n");

// for (i = 0; i < DIMENSION; printf("\n%d", ar[i++]));

printf("\n stime - ftime = %d", stime - ftime);

getchar();

free(ar);

}

3.2 5000, 50000, 500000 . . .

3.3. , , 2.3, . , , .

3.4 , .

3.5 , .

 

// C/++ -> ; /MTd

// ->-> ; uafxcwd.lib

 

#include "stdafx.h"

#include "afxwin.h"

#include "iostream"

using namespace std;

void main(){

HWND hwnd;

hwnd=FindWindow(_T("ConsoleWindowClass"),_T("C:\\Windows\\system32\\cmd.exe"));

if (hwnd!=NULL){

HDC hdc;

hdc=GetWindowDC(hwnd);

POINT pt[3];

CPoint pt1(100,100), pt2(200,200);

pt[0].x = 0;pt[0].y=0; pt[1].x = 100;pt[1].y=100; pt[2].x = 50;pt[2].y=100;

if (hdc!=0){

CPen pen(PS_SOLID,4,RGB(255,0,0));

SelectObject(hdc,pen);

Ellipse(hdc,90,100,120,150);//

Arc(hdc,pt1.x,pt1.y,pt2.x,pt2.y,100,200,100,100);//

Polyline(hdc,pt,3); //

getchar();

for(int i=0; i < 100; i++){ //

CPen pen1(PS_SOLID,4,RGB(0,255,0));

SelectObject(hdc,pen1);

Arc(hdc,pt1.x,pt1.y,pt2.x,pt2.y,100,200,100,200);//

Sleep(24);// 24

CPen pen2(PS_SOLID,4,RGB(0,0,0));

SelectObject(hdc,pen2);

Arc(hdc,pt1.x,pt1.y,pt2.x,pt2.y,100,200,100,200);//

pt1.x+=1; pt1.y+=1;pt2.x+=1;pt2.y+=1; //

}

ReleaseDC(hwnd, hdc);

}

else cout << "Error DC Window" << endl;

}

else cout << "Error Find Window" << endl;

}

3.6. , .

3.7. .

3.8. .

3.9. .

 

4.1 . ..

4.2 3.2, 3.3, 3.4 3.7.

 

5.1 ?

5.2 ?

5.3 main ?

5.4 ? ?

5.5 ? ?

5.6 .

5.7 ? .

5.8 , ?

5.9 .

5.10 , 2.2. .

5.11 ?

5.12. :

{6,2,1,3,4,5,8,7,0}.

5.13. ? ?

 

6



<== | ==>
, | , .
:


: 2018-11-11; !; : 473 |


:

:

,
==> ...

1876 - | 1716 -


© 2015-2024 lektsii.org - -

: 0.281 .