.


:




:

































 

 

 

 


Book




package cjLab1_k2_1;

 

Class Book

{

private int pages;

private String name;

public void SetPages (int Pages) {pages= Pages;}

public int GetPages () {return pages;}

public void SetName (String Name) {name= Name;}

public String GetName () {return name;}

}

 

class Class1

{

public static void main()

{

Book book= new Book();

book.SetName("BOOK");

book.SetPages(500);

 

System.out.println("book.name= " + book.GetName());

System.out.println("book.pages= " + book.GetPages());

}

}

 

 

 

package cjLab1_k2_1;

 

class Book

{

private int pages;

private String name;

 

public void SetPages (int Pages) {pages= Pages;}

public int GetPages () {return pages;}

public void SetName (String Name) {name= Name;}

public String GetName () {return name;}

}

 

class ManualBook extends Book

{

boolean manual;

 

public void SetMenual (boolean Manual) {manual= Manual;}

public boolean IsManual () {return manual;}

}

 

class Class1

{

public static void main()

{

ManualBook manualBook= new ManualBook();

manualBook.SetName("BOOK");

manualBook.SetPages(500);

manualBook.SetMenual (true);

 

System.out.println("book " + manualBook.GetName()+

" contains " + manualBook.GetPages()+ " pages");

 

if (manualBook.IsManual()) System.out.println("book is manual\n");

else System.out.println("book isn't manual\n");

}

}

 

 

4) Calc accumulator :

 

void Init (int n) accumulator

n,

int Get () accumulator,

void Add (int n) n accumulator,

void Sub (int n) n accumulator.

 

5) SecondCalc, Calc

 

void Mul (int n) accumulator n.

 

6) ThirdCalc, SecondCalc

 

void ChangeSign () accumulator,

bool IsSign () accumulator.

 

7) FourthCalc, ThirdCalc

 

void ChangeSign () accumulator,

bool IsSign () accumulator.

 

3. ++/CLI

++.NET

 

/////////////////////////

// ccLab1k2_1

 

#include "stdafx.h"

#using <mscorlib.dll>

 

using namespace System;

 

int _tmain()

{

// TODO: Please replace the sample code below with your own.

Console::WriteLine(S"Hello World");

return 0;

}

 

Book

 

/////////////////////////

// C++.NET File ccLab1k2_1

// Book

#include "stdafx.h"

//#using <mscorlib.dll>

//#include <stdio.h>

//#include <string.h>

 

//using namespace System;

 

struct Book

{

int pages;

char name [20];

};

 

int _tmain ()

{

// TODO: Please replace the sample code below with your own.

//Console::WriteLine (S"Hello World");

printf ("Hello!\n");

Book book;

book.pages= 500;

strcpy (book.name, "BOOK");

printf ("book %s contains %d pages\n", book.name, book.pages);

return 0;

}

 

Book

/////////////////////////

// C++.NET File ccLab1k2_2

// Book

#include "stdafx.h"

 

class Book

{

public:

int pages;

char name [20];

};

 

int _tmain ()

{

printf ("Hello!\n");

Book book;

book.pages= 500;

strcpy (book.name, "BOOK");

printf ("book %s contains %d pages\n", book.name, book.pages);

return 0;

}

=========================================

/////////////////////////

// C++.NET File ccLab1k2_2

// Book

#include "stdafx.h"

 

class Book

{

int pages;

char name [20];

public:

void SetPages (int Pages) {pages= Pages;}

int GetPages () {return pages;}

void SetName (char* pName) {strcpy (name, pName);}

char* GetName () {return name;}

};

 

int _tmain ()

{

printf ("Hello!\n");

Book book;

//book.pages= 500;

book.SetPages (300);

//strcpy (book.name, "BOOK");

book.SetName ("BOOK");

printf ("book %s contains %d pages\n ", book.GetName (),

book.GetPages ());

return 0;

}

 

 

/////////////////////////

// C++.NET File ccLab1k2_4

// Book

#include "stdafx.h"

 

class Book

{

int pages;

char name [20];

public:

void SetPages (int Pages) {pages= Pages;}

int GetPages () {return pages;}

void SetName (char* pName) {strcpy (name, pName);}

char* GetName () {return name;}

};

 

class BookOther: public Book

{

bool manual;

public:

void SetMenual (bool Manual) {manual= Manual;}

bool IsManual () {return manual;}

};

 

int _tmain ()

{

printf ("Hello!\n");

BookOther book;

book.SetPages (300);

book.SetName ("BOOK");

book.SetMenual (true);

 

printf ("book %s contains %d pages\n", book.GetName (),

book.GetPages ());

if (book.IsManual()) printf ("book is manual\n");

else printf ("book isn't manual\n");

return 0;

}

 

 

8) Calc :

 

void Init (int n) accumulator

n,

int Get () accumulator,

void Add (int n) n accumulator,

void Sub (int n) n accumulator.

 

9) OtherCalc,

 

void Mul (int n) accumulator n.

 

10) AnotherCalc, OtherCalc

 

void ChangeSigh () accumulator,

bool IsSigh () accumulator.

 

 





:


: 2016-09-03; !; : 212 |


:

:

, ,
==> ...

1540 - | 1462 -


© 2015-2024 lektsii.org - -

: 0.035 .