0% found this document useful (0 votes)
86 views13 pages

Mecadineoba # 2: Praqtikuli Mecadineobis Temebi: Laboratoriuli Mecadineobis Temebi

The document provides examples of practical and laboratory topics in programming. Practical programming topics include standard data type operations and arithmetic and logical operators. Laboratory programming topics include input and output of strings, input and output of multiple integer values, and program flow control. The document then provides sample programs and output for various data type operations and arithmetic operator usage. It asks the reader to determine the value or type of various variables and expressions. Finally, it asks the reader to write a program that sums the digits of an integer number entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views13 pages

Mecadineoba # 2: Praqtikuli Mecadineobis Temebi: Laboratoriuli Mecadineobis Temebi

The document provides examples of practical and laboratory topics in programming. Practical programming topics include standard data type operations and arithmetic and logical operators. Laboratory programming topics include input and output of strings, input and output of multiple integer values, and program flow control. The document then provides sample programs and output for various data type operations and arithmetic operator usage. It asks the reader to determine the value or type of various variables and expressions. Finally, it asks the reader to write a program that sums the digits of an integer number entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

mecadineoba # 2

praqtikuli mecadineobis Temebi: laboratoriuli mecadineobis Temebi:


 standartuli tipis cvladebis beWdva  striqonebis wakiTxva da beWdva
 ariTmetikuli da Sedarebis operatorebi  mTeli ricxvebis wakiTxva
amocanebi:  3 ricxvis saSualo ariTmetikuliM

1-5. ipoveT cvladis mniSvneloba, Tu...…>>> amocanebi:


6. daadgineT cvladis tipi… >>> 1. striqonebis Setana klaviaturidan da
7. romlis mniSvnelobaa meti? >>> gamotana ekranze >>>
8-9. cvladebis mniSvnelobebis gacvla >>> 2. striqonebis da mTeli ricxvebis Setana-
gamotana >>>
10. samniSna ricxvis cifrebis povna >>>
3. programa gekiTxebaT... >>>
damoukidebeli samuSao >>>
4. cvladebis diapazonebi >>>
damoukidebeli samuSao >>>

masala damoukideblad gacnobisaTvis:


1. standartuli tipis cvladebis beWdvis nimuSebi:
# programis fragmenti Sedegi
1 cout << 1111 << 5555 << "AAAA"; 11115555AAAA
1111
cout << 1111 << endl << 5555 << endl << "AAAA" 5555
2
<< endl; AAAA

11.11
0
cout << 11.11 << endl << false << endl << true << endl
3 1
<< 'a' <<endl;
A

double d = 12.00357; 12.0036


4
cout << d << endl << 'd' << endl; d
int a = 1111; a
5
cout << 'a' << endl << a << endl; 1111

SeniSvna 1: aq da qvemoT, imisaTvis rom vnaxoT programis fragmentis Sedegi, igi unda
SevavsoT srul programul kodamde. magaliTad, mexuTe fragmentisTvis unda
davweroT:
#include <iostream>
using namespace std;
int main()
{
int a = 1111;
cout << 'a' << endl << a << endl;
}
xolo sxva nimuSebSi SevcvaloT erTi fragmenti meoreTi.

SeniSvna 2: C++ -Si, return 0; instruqcia main() – Si aucilebeli aRar aris.

2. operatorebis gamoyenebis nimuSebi:


# programis fragmenti Sedegi
int b = 2;
1 b += 3; b gaxda 5
cout << "b gaxda " << b << endl;
კ. გელაშვილი, ი. ხუციშვილი 7
double k = 5.0148;
2 k += 6; k udris 11.0148
cout << "k udris " << k << endl;
int b = 2; double p = 2.5;
b *= 2; p *= 2; b udris 4
3
cout << "b udris " << b << endl p udris 5
<< "p udris " << p << endl;
int n = 20; double q = -25;
n /= 6; q /= 6; n udris 3
4
cout << "n udris " << n << endl q udris -4.16667
<< "q udris " << q << endl;
int c = 15;
5 c %= 9; c udris 6
cout << "c udris " << c << endl;
string name = "George";
George
6 cout << name << endl;
George Lukas
cout << name + ' ' + "Lukas" << endl;
string name = "George";
7 name += " Lukas"; George Lukas
cout << name << endl;
char c = 'F';
8 c += 1; G
cout << c << endl;
int m = 11; 11
cout << m++ << endl; 12
9
cout << m << endl; 13
cout << ++m << endl << m << endl; 13
char c = 'A';
cout << c++; /პოსტიქსური
10 ABCC
cout << c;
cout << ++c << c << endl; // პრეფიქსური

3. rogor muSaobs Sedarebis operatorebi


# programis fragmenti Sedegi
1 cout << (37 == 42) << endl; 0 // mcdari
2 cout << (25 > 17) << endl; 1 // WeSmariti
int i = 7, j = 5;
3 1 // WeSmariti
cout << (i >= j) << endl;
int a = 55, b = 15;
4 0 // mcdari
cout << (a <= b) << endl;
string name = "George";
5 1 // WeSmariti
cout << (name == "George") << endl;
string name = "George";
6 0 // mcdari
cout << (name != "George") << endl;
double p = 1.051, q = 1.05;
7 1 // WeSmariti
cout << (p > q) << endl;
double x = -0.000045, y = -0.0045;
8 0 // mcdari
cout << (x <= y) << endl;

saauditorio samuSao:
<<< 1. ipoveT m cvladis mniSvneloba, Tu mocemuli gvaqvs ganacxadi int m = 4;
a) m += 3 b) m *= 3 g) m -= ‘M’; d) --c
2. ipoveT c cvladis mniSvneloba, Tu mocemuli gvaqvs ganacxadi char c = 'D';
a) c += 3; b) c -= 3; g) c = 'M'; d) --c;
3. ipoveT s cvladis mniSvneloba, Tu gvaqvs ganacxadi string s = "String";

კ. გელაშვილი, ი. ხუციშვილი 8
a) s += " AAAA"; b) s = s+' '+"AAAA"+'.'; g) s = "UUUH!";
4. ipoveT x cvladis mniSvneloba, Tu gvaqvs ganacxadi double x = 11.907;
a) x++; b) x =(x - 1.907)/3; g) x -= 11.807; d) x += -5;
5. vTqvaT, m da n int tipis cvladebia. ipoveT maTi mniSvnelobebi:
a) m = (7 - 3)*9; b) n = (4 + 7)/3*2; g) n = m = (10 + 8)/6;
d) n = 4 + 5*(m = 7/3); e) m = (8 + 2)*2.5; v) n = (2 + 3)*2.5;
z) n = (int)5.5 + 4.7;
<<< 6. a) s cvlads mianiWeT mTeli a, b da c ricxvebis saSualo ariTmetikuli. zusti
Sedegis misaRebad rogori tipis unda iyos s?

(a+b+c)/3.0 double S ;

ანუ a b c ინტებია მარა პასუხი რომ დაბლი იყოს ამიტომ მნიშვნელი 3,0 უნდა იყოს

b) k cvlads mianiWeT mTeli n da m ricxvebis sxvaobis mecxredi. zusti Sedegis misaRebad


rogori tipis unda iyos k?

k= (n-m)/9.0

g) C cvlads mianiWeT mTeli A da B ricxvebis jamis 4-ze gayofisas miRebuli ricxvis mTeli
nawili. daadgineT C cvladis tipi.
C= (a+b)/4
Int 4
C int
<<< 7. rogor gavarkvioT ori cvladidan romlis mniSvnelobaa meti? axseniT ras dabeWdavs
Semdegi programa.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n = 3, m = 2;
cout << (n == m) << '\t'
<< (n > m) << endl;
char p = 'B', c = 'Q';
cout << (p != c) << '\t'
<< (p <= c) << endl;
double x = 10.5, y = -0.25;
cout << (x < y) << '\t'
<< (x >= y) << endl;
string S = "Anano", Q = "Aniko";
cout << (S > Q) << '\t'
<< (S < Q) << endl;
}
pasuxi:

კ. გელაშვილი, ი. ხუციშვილი 9
0 1
1 1
0 1
0 1
Press any key to continue . . .

<<< 8. ra mniSvnelobebs miiRebs m da n cvladebi?


int m = 5, n = 3;
m = n; n = m;
m==3
n==3
ავტორს უნდოდა ერთმანეთის მნიშვნელობა მიანიჭოს ორ ცვლადს დამატებითი ცვლადის გარეშე

9. axseniT sityvebiT, ras akeTebs kodis Semdegi ori fragmenti:


a) int m = 9, n = 5, k;
k = m;9
m = n;5
n = k;9
cout << x << ' ' << y << endl;

ეს კოშკების ალგორითმის ამბავია, ანუ მესამე ცვლადი შემოდის და იმას ვაძლევთ მნიშვნელობას,
ამ ცვლადის გამოყენებით კი მ -ს და ნ -ს ვუცვლით მნიშვნელობებს ერთმანეთში;

b) int m = 9, n = 5;
m = n + m;14
n = m - n;9
m = m - n;5
cout << m << ' ' << n << endl;
ამ მინიჭების ოპერაციებით ვცვლით მნიშვნელობებს დამატებითი ცვლადის გარეშე;
სტრიქონებთან ამას ვერ გამოვიყენებთ რადგან სტრიქონებისთვის „+“ არის განსაზღვრული მარა ‘-‘ არაა
განსაზღვრული

<<< 10. mocemulia samniSna ricxvi n.


a) dabeWdeT n ricxvis cifrTa jami.
#include <iostream>
using namespace std;
int main()

{
int n, sum;
cout << "Enter integer\n";
cin >> n;
sum = n/100 + (n/10)%10 + n%10;
cout << "sum = " << sum << endl;
}

programis Sedegia:
Enter integer
537
კ. გელაშვილი, ი. ხუციშვილი 10
sum = 15
Press any key to continue . . .
b) mTel k cvlads mianiWeT samniSna m ricxvis Sebrunebuli rigiT aRebuli cifrebisgan Sed-
genili ricxvi da dabeWdeT.
#include <iostream>
using namespace std;
int main()
{
int m, k;
cout << "Enter m" << endl;
cin >> m;
k = 100*(m%10) + 10*((m/10)%10) + m/100;
cout << "k = " << k << endl;
cout << ++k << endl; // პრეფიქსური ინკრემენტი

}
programis Sedegia:
Enter m
357
k = 753
Press any key to continue . . .

პოსტფიქსური ინკრემენტით
#include <iostream>
using namespace std;
int main()
{
int m, k;
cout << "Enter m" << endl;
cin >> m;
k = 100*(m%10) + 10*((m/10)%10) + m/100;
cout << "k = " << k << endl;
cout << k++ << endl; // პოსტფიქსური ინკრემენტი , აქ გამოაქვს ჯერ ისევ კ
cout << k << endl; // პოსტფიქსი აქ ემატება და კ+1 გამოაქვს
}

<<< damoukidebeli samuSao:


1. a) A cvlads mianiWeT mTeli B da D ricxvebis jamis mesamedi. zusti Sedegis misaRebad
rogori tipis unda iyos A?

კ. გელაშვილი, ი. ხუციშვილი 11
int main()
{
int b, d;
cout << "sheikvane b da d" << endl;
cin >> b >> d;

double A;
A = (b + d) / 3.;
cout << " b da ds mesamedia " << A << endl;
}

b) gansazRvreT d cvladis tipi da d –s mianiWeT p ricxvis meoTxedisa da q ricxvis meeqvsedis


sxvaoba, Tu :
- p da q mTeli ricxvebia;

int p, q;
cout << "sheikvane p da q\n";
cin >> p >> q;
double d;
d = p / 4 - q / 6.;
cout << "p da q s sxvobaa " << d << endl;

- p da q namdvili ricxvebia.
double p, q;
cout << "sheikvane p da q\n";
cin >> p >> q;
double d;
d = p / 4 - q / 6.;
cout << "p da q s sxvobaa " << d << endl;

2. ipoveT n cvladis mniSvneloba, Tu mocemuli gvaqvs ganacxadi int m = 7, n = 9;


a) n =(m == n); b) n =(m < n); g) n =(m > n); d) n = m <= n;
e) m = m != n; v) m += n; z) n *= m-1; T) n /= m+1; i) n += 2*m-n.

int main()
{
double m, n;

m = 7;
n = 9;
n += 2 * m - n;
cout << n;
}

3. SeamowmeT kompiuterze da gaaanalizeT miRebuli pasuxebi (SeavseT cxrili):


# Pprogramis fragmenti Sedegi
int x = 1, z;
z = x++;
1
cout << "x = " << x
<< "\tz = " << z << endl;
int x = 1, z; X=2
z = ++x;
2 Z=2
cout << "x = " << x
<< " z = " << z << endl;
char s = 'B', t; s=A
t = s--;
3 t=b
cout << "s = " << s
<< "\tt = " << t << endl;
კ. გელაშვილი, ი. ხუციშვილი 12
char s = 'B', t; T=a
t = --s;
4 S=a
cout << "s = " << s
<< "\nt = " << t << endl;
double d = 15.674, q; Q=6.674
q = ++d - 10;
5 D= 16.674
cout << "d = " << d
<< " q = " << q << endl;
double d = 15.674, q; q=25.674
q = d-- + 10;
6 d= 14.674
cout << "d = " << d
<< " q = " << q << endl;
string S = "Hello", K = "Students"; Hello
7 S += ", " + K + '!'; students!
cout << "S = " << S << endl;
bool b = false; 0
cout << ++b << endl;
8
b -= 1;
cout << b << endl;

4*. ra Sedegi miiReba programis Semdegi fragmentis SesrulebiT?


cout << (0.3 == 3*0.1) << endl;
bechdavs 0 რადგან 3*0,1 == 0,3000000004

miTiTeba: miRebuli pasuxis axsnisTvis CaamateT programaSi


#include <iomanip>
da dabeWdeT 3*0.1 –is mniSvneloba 20 aTwiladi niSnis sizustiT:
cout << fixed << setprecision(20);
cout << 3*0.1 << endl;
5. axseniT, ras dabeWdavs programis Semdegi fragmenti da ratom:
a) string a = "stumari", b = "studenti";
cout << (a < b) << endl << (a != b) << endl;
0
1
რადგან a>b , a!=b
b) string c = "kargi ";
cout << (c + "amindi" >= c + "ambavi") << endl;
ibechdeba 1
radgan amindi > ambavi

g) string k = "Word", m = "Excel";


cout << (k > m) << '\t';
cout << (k = m) << endl;
cout << (k == m) << endl;
1
კ. გელაშვილი, ი. ხუციშვილი 13
Excel
1
Radgan k=m mashin k==m
6. axseniT, ras akeTebs kodis Semdegi sami fragmenti:
a) char p = '!', c = '?', d;
d = p; p = c; c = d;
cout << p << ' ' << c << endl;
cvlis cvladebis mnishvnelobebs
shemodis mesame cvladi
d= !
p=?
c=!
cout ? !
b) bool t = true, f = false, d;
d = f; f = t; t = d;
cout << boolalpha << "t gaxda " << t
<< endl << "f gaxda " << f << endl;
D=0
F=1
T=0
Cout false true

g) string S = "Gel", Q = "Euro", P;


P = S; S = Q; Q = P;
cout << S << '\t' << Q << endl;
cout euro Gel
7. SeamowmeT, ras dabeWdavs Semdegi programa da axseniT:
#include <iostream>
using namespace std;
int main()
{
char x = '*';
cout << x << ' ' << (int)x << endl;
int p = 127;
cout << (char)p << " simbolos kodi = "
<< p << endl;
}

8. d cvlads rigrigobiT mianiWeT a ricxvis yvela cifri, Tu:


a) a aris oTxniSna mTeli ricxvi;

int a;
double d;

კ. გელაშვილი, ი. ხუციშვილი 14
cout << "sheikvanet otxnishna cifri\t";
cin >> a;
d = a / 1000;
cout << d<<endl;
d= (a / 100) % 10;
cout << d<<endl;
d= (a / 10) % 10;
cout << d<<endl;
d= (a % 1000) % 10;
cout << d<<endl;

b) a aris xuTniSna mTeli ricxvi.


int a;
double d;
cout << "sheikvanet otxnishna cifri\t";
cin >> a;
d = a / 10000;
cout << d<<endl;
d= (a / 1000) % 10;
cout << d<<endl;
d= (a / 100) % 10;
cout << d<<endl;
d= (a % 100)/10;
cout << d<<endl;
d = a % 10;
cout << d << endl;

9. mocemulia samniSna N ricxvi. dabeWdeT N ricxvis cifrebi Sebrunebuli rigiT.


int n,d;
cout << "sheikvanet samnishna ricxvi\n";
cin >> n;
d = 100 * (n % 10) + 10 * ((n % 100) / 10) + n / 100;

cout << d << endl;

კ. გელაშვილი, ი. ხუციშვილი 15
laboratoriuli samuSao:

<<< amocana 1. striqonis Setana klaviaturidan da gamotana ekranze.


///////////////////////////////////////
// ავტორი:
// პროგრამა: სახელის წაკითხვა და ბეჭდვა
// თარიღი:
///////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Please enter your first name"
" (followed by 'Enter'):\n";
string first_name;
cin >> first_name;
cout << "Hello, " << first_name << "!\n";
}
davaleba: gauSviT programa Sesrulebaze: SeitaneT klaviaturidan Tqveni saxeli, bolos daaWireT
Enter –s (riTac daafiqsirebT Setanil informacias). gaaanalizeT miRebuli Sedegi..

<<< amocana 2. striqonis da mTeli ricxvis Setana klaviaturidan da gamotana ekranze.


////////////////////////////////////////////////
// ავტორი:
// პროგრამა: სახელის და ასაკის წაკითხვა და ბეჭდვა
// თარიღი:
////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Please enter your first name"
" and age:\n";
string first_name;
int age;
cin >> first_name >> age;
cout << "Hello, " << first_name << "!\n"
<< "You are " << age << " years old" << endl;
}
davaleba: gauSviT programa Sesrulebaze: SeitaneT klaviaturidan Tqveni saxeli da asaki, Setana
daasruleT Enter –ze daWeriT. gaaanalizeT miRebuli Sedegi.

<<< amocana 3. programa “gekiTxebaT” Tqven saxelsa da gvars da Semdeg beWdavs misalmebis
striqons.
/////////////////////////////////////////////////
// ავტორი:
// პროგრამა: სახელისა და გვარის წაკითხვა და ბეჭდვა
/////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;
int main()
კ. გელაშვილი, ი. ხუციშვილი 16
{
cout << "Please enter your first name:\n";
string first_name;
cin >> first_name;
cout << "Please enter your last name:\n";
string last_name;
cin >> last_name;
cout << "Please enter your age:\n";
int age;
cout << "Hello, " << first_name << ' '
<< last_name<< ‘ ‘ <<age<<end;
}

//Programa ასაკს +3 წელთან ერთად

#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Please enter your first and last name:\n"
" and also age\n";
string first_name, last_name;
int age;
cin >> first_name >> last_name >> age;
cout << "Hello, " << first_name << ' '

<< last_name << endl


<< "after 3 years your age will be " << age + 3 << endl;
}

davaleba:
a) gauSviT programa Sesrulebaze: SeitaneT klaviaturidan Tqveni saxeli da Semdeg gvari.
gaaanalizeT miRebuli Sedegi.
b) gadawereT programa: pirveli 6 striqoni SecvaleT Semdegi 3 -iT
cout << "Please enter your first and last names\n";
string first_name, last_name;
cin >> first_name >> last_name;
kvlav gauSviT programa Sesrulebaze da SeitaneT klaviaturidan Tqveni saxeli da gvari.
gaaanalizeT miRebuli Sedegi.

<<< amocana 4. dabeWdeT sxvadasxva tipebisTvis maTi warmodgenis udidesi da umciresi


mniSvnelobebi
////////////////////////////////////////////
// ავტორი:
// პროგრამა: უდიდესი და უმცირესი სიდიდეები
// თარიღი:
////////////////////////////////////////////
კ. გელაშვილი, ი. ხუციშვილი 17
a) mTeli tipebisa:
#include <iostream>
#include <climits>
using namespace std;
int main()
{
cout << INT_MIN << '\t' << INT_MAX << endl;
cout << 0 << '\t' << UINT_MAX << endl;
cout << CHAR_MIN <<'\t'<< CHAR_MAX << endl;
cout << 0 << '\t' << UCHAR_MAX << endl;
cout << SHRT_MIN << '\t' << SHRT_MAX << endl;
cout << 0 << '\t' << USHRT_MAX<<endl;
cout << LONG_MIN << '\t' << LONG_MAX << endl;
cout << 0 << '\t' << ULONG_MAX << endl;
cout << sizeof(long long) << endl;
cout << LLONG_MIN << '\t' << LLONG_MAX << endl;
cout << 0 << '\t' << ULLONG_MAX << endl;
}
b) namdvili tipebisa:
#include <iostream>
#include <cfloat>
using namespace std;

int main()
{
cout << FLT_MIN << '\t' << FLT_MAX << endl;
cout << DBL_MIN << '\t' << DBL_MAX << endl;
}
davaleba: gauSviT programa Sesrulebaze: SeitaneT klaviaturidan sami mTeli ricxvi da
gaaanalizeT miRebuli Sedegi.

<<< damoukidebeli samuSao:


1. mocemuli sami mTeli ricxvisTvis, x cvlads mianiWeT maTi saSualo ariTmetikuli da
dabeWdeT igi.
Sesabamisi C++ –programis saxea:
///////////////////////////////////////////////
// ავტორი:
// პროგრამა: სამი რიცხვის საშუალო არითმეტიკული
///////////////////////////////////////////////
#include <iostream>
using namespace std;
int main(){
int a, b, c;
cout << "Enter 3 integers :\n";
cin >> a >> b >> c;
double x;
x = (a + b + c)/3.; // საშუალო
cout << "The average is " << x << endl;
}

კ. გელაშვილი, ი. ხუციშვილი 18
davaleba: gauSviT programa Sesrulebaze: SeitaneT klaviaturidan sami mTeli ricxvi da
gaaanalizeT miRebuli Sedegi.
2.ra moxdeba, Tu mTeli ricxvi ufro meti aRmoCndeba, vidre amas am ricxvisaTvis arCeuli tipi
iTvaliswinebs?
gaarCieT programa:
#include <iostream>
#include <climits>
using namespace std;
int main()
{
int m = INT_MAX, n = INT_MIN;
cout << "m = " << m << '\t'
<< "m + 1 = " << m + 1 << '\t'
<< "m + 2 = " << m + 2 << endl;
cout << "n = " << n << '\t'
<< "n - 1 = " << n – 1 << '\t'
<< "n - 2 = " << n – 2 << endl;

char a = 127, b(100);


a += b;
cout << (int)a << endl;

}
davaleba:
a) SeasruleT mocemuli programa. gaaanalizeT miRebuli Sedegebi.
b) SeasworeT programa da SeasruleT igive operaciebi uniSno mTeli tipis ricxvebisTvis (tipi
unsigned int). gaiTvaliswineT, rom am SemTxvevaSi m = UINT_MAX, n = 0.
g) igive eqsperimenti CaatareT char tipis SemTxvevaSi.

კ. გელაშვილი, ი. ხუციშვილი 19

You might also like