- •Практичне заняття 8 Теоретична частина
- •Завдання
- •Int main()
- •Void push(int var)
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 9 Теоретична частина
- •Зміст завдання
- •Лабораторне заняття 10 Теоретична частина
- •Практичне заняття 9 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Практичне заняття 10-11 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 11-12 Теоретична частина
- •Завдання 1
- •Завдання 2
- •Завдання 3
- •Int main()
- •Практичне заняття 12-13 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 13 Теоретична частина
- •Завдання 1
- •Int main()
- •Завдання 2
- •Практичне заняття 14 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Лабораторне заняття 14 Теоретична частина
- •Завдання
Практичне заняття 9 Теоретична частина
Базується на матеріалі лекцій 20-21: вказівники
Завдання
Ввести тексти програм, які розглядалися у лекціях 20-21. Прокомпілювати, проаналізувати результат роботи. До тексту звіту включити лістінги програм та результати їх роботи.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
#include<string.h>
Int main()
{clrscr();
char* str="Пробна фраза";
int len=strlen(str); //довжина рядка
char* ptr;
ptr=new char[len+1]; //виділення памяті
strcpy(ptr,str);
cout<<"ptr="<<ptr<<endl;
delete[]ptr; //вивільнення памяті
bioskey(0);
return 0;
}
Програма 20.15
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
#include<string.h>
class String
{private:
char* str;
public:
String(char* s)
{int length=strlen(s);
str=new char[length+1];
strcpy(str,s);
}
~String()
{cout<<”Видалення рядка\n”;
delete[]str;
}
void display()
{cout<<str<<endl;
}
};
///////////////////
Int main()
{clrscr();
String s1=”Пробна фраза”;
cout<<”s1=”;
s1.display();
return 0;
}
Програма 20.16
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class Distance
{private:
int feet;
float inches;
public:
void getdist()
{cout<<"\nВведіть фути";cin>>feet;
cout<<"\nВведіть дюйми";cin>>inches;
}
void showdist()
{cout<<feet<<"\'="<<inches<<'\"';}
};
/////////////
Int main()
{clrscr();
Distance dist;
dist.getdist();
dist.showdist();
Distance* distptr;
distptr=new Distance;
distptr->getdist();
distptr->showdist();
cout<<endl;
bioskey(0);
return 0;
}
Програма 20.17
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class person
{private:
char name[40];
public:
void SetName()
{cout<<"Введіть імя:";cin>>name;
}
void PrintName()
{cout<<"\n Імя:"<<name;
}
};
///////////
Int main()
{clrscr();
person* persPtr[100];
int n=0;
char choice;
do
{persPtr[n]=new person;
persPtr[n]->SetName();
n++;
cout<<"Continue (y/n)?";cin>>choice;
}
while(choice=='y');
for(int j=0;j<n;j++)
{cout<<"\nІнформація про N"<<j+1;
persPtr[j]->PrintName();
}
cout<<endl;
bioskey(0);
return 0;
}
Програма 20.18
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
struct link
{int data;
link* next;
};
class linklist //список
{private:
link* first;
public:
linclist()
{first=NULL;}
void additem(int d);
void display();
};
////////////////////
void linklist::additem(int d)
{link* newlink=new link;
newlink->data=d;
newlink->next=first;
first=newlink;
}
void linklist::display()
{link* current=first;
while(current)
{cout<<current->data<<endl;
current=current->next;
}
}
////////////////
Int main()
{clrscr();
linklist l1;
l1.additem(25);
l1.additem(35);
l1.additem(45);
l1.display();
bioskey(0);
return 0;
}
Програма 20.19
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
#include<string.h>
class person
{protected:
char* name;
public:
void setname()
{cout<<”Name=”;cin>>name;}
void printname()
{cout<<endl<<name;}
char* getname()
{return name;}
};
///////////////
