You are on page 1of 33

,

-11

: . //


.
.
www.emust.edu.mn


.
.

A) #include <iostream>
using namespace std;
int main()
{
char str[14] = {'C','+','+','p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g'};
for(int i;i<14;i++)
cout<<"str["<<i<<"]="<<str[i]<<endl;
}

B) char string[16]="C++ programming";



:
str[0]=C
str[1]=+
str[2]=+
str[3]=p
str[4]=r
str[5]=o
str[6]=g
str[7]=r
str[8]=a
str[9]=m
str[10]=m
str[11]=i
str[12]=n
str[13]=g


.

#include <iostream>
using namespace std;
int main()
{
char str[100];
cout << "Temdegt muruu oruul: ";
cin >> str;
cout << "Tanii oruulsan temdegt mur: " << str << endl;
cout << "\n Ta dahiad uur temdegt mur oruulna uu: ";
cin >> str;
cout << "Tanii oruulsan temdegt mur: "<<str<<endl;
return 0; }

:
Temdegt muruu oruul: ILOVEMONGOLIA
Tanii oruulsan temdegt mur: ILOVEMONGOLIA

Ta dahiad uur temdegt mur oruulna uu: WE Love Mongolia


Tanii oruulsan temdegt mur: WE

--------------------------------
Process exited after 10.13 seconds with return value 0
Press any key to continue . . .


.

. , cin
.

.
. C++-
0- .
null cout
null .


.

.
C++-
.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int max=20;
char str[max];
cout << "\n Mur oruulj ugnuu: ";
cin >> setw(max) >> str;
cout << "Tanii oruulsan mur: " << str;
}

:

Mur oruulj ugnuu: hi mongolia


Tanii oruulsan mur: hi
--------------------------------
Process exited after 5.053 seconds with return value 0
Press any key to continue . . .

setw
.
str 19- . ,
null 1 .

#include <iostream>
using namespace std;

int main()
{
char str[100];
cout << "Temdegt moroo oruul: ";
cin.get(str, 100);

cout << "Tanii oruulsan: " << str << endl;


return 0;
}

:

Temdegt moroo oruul: Mongolian University Science of Technology


Tanii oruulsan: Mongolian University Science of Technology

--------------------------------
Process exited after 24.76 seconds with return value 0
Press any key to continue . . .

//strinit.cpp
#include <iostream>
using namespace std;
int main()
{
char str[]="Bid programchlaliin hel surj bn";
cout << str;
}

:

Bid programchlaliin hel surj bn


--------------------------------
Process exited after 0.01883 seconds with return value 0
Press any key to continue . . .

,
.
, . (
). C++-
.


,
. ..

: Law is bottomless pit.


: Law

C++- cin space-


. :

cin >> var1 >> var2 >> var3;

15 25 35

. var1 15, var2 25, var3 35


.

. space
.


#include <iostream>
using namespace std;

int main()
{
const int max=80;
char str[max];
cout << "\n Mor oruulj ogno uu: ";
cin.get(str, max);
cout << "Oruulsan mor: "<< str;
}

:

Mor oruulj ogno uu: Mongolian people republic


Oruulsan mor: Mongolian people republic
--------------------------------
Process exited after 12.82 seconds with return value 0
Press any key to continue . . .


? cin get
3 . 3
. .. 3
Enter .
.

:
#include <iostream>
using namespace std;
int main()
{
const int max=2000;
char str[max];
cout << "\n Moroo oruulj ogno uu: \n";
cin.get(str, max, '$');
cout << "Oruulsan moruud:\n" << str;
}

. $
2000-
.
:
Moroo oruulj ogno uu:
Mongol ruler and founder
of the Golden Horde
division of the
Mongol Empire$

Oruulsan moruud:
Mongol ruler and founder
of the Golden Horde
division of the
Mongol Empire


.
.


#include <iostream>
#include <string.h>
using namespace std;
int main(){
const int max=1000;
int j;
char str1[]="Batu khan Mongol ruler and founder of the Golden Horde, division
of the Mongol Empire."
"Batu was a son of Jochi and grandson of Genghis Khan";
char str2[max];
for (j=0; j<strlen(str1); j++)
str2[j]=str1[j];
str2[j]='\0';
cout<<endl<<str2;}

:

Batu khan Mongol ruler and founder of the Golden Horde, division of the
Mongol Empire.Batu was a son of Jochi and grandson of Genghis Khan
--------------------------------
Process exited after 0.0205 seconds with return value 0
Press any key to continue . . .

2
. str1-
str2- .
. string.h .
. strlen()
.
str1-
. null
str2 null .


.



.


#include <iostream>
#include <string.h>
using namespace std;
int main()
{
const int max=80;
char str1[]=" His ulus was the chief state of the Golden Horde, which ruled Rus',
Volga Bulgaria"
" Cumania, and the Caucasus for around 250 years";
char str2[max];
strcpy(str2, str1);
cout << endl << str2;}
, 1- , 2-
.


#include <iostream>
using namespace std;
int main(){
string str = "Sumiya garag /Saran odor/, Angarag garag/Gal odor/, Bud
garag/Usan odor/ Barkhasbadi garag /Modon odor/ Sugar garag /Tomor odor/,
Sanchir garag /Shoroon odor/ Adiya garag /Naran odor/";
// you can also use str.length()
cout << "String Length = " << str.size();
return 0;}
:
String Length = 186
--------------------------------
Process exited after 0.01945 seconds with return value 0
Press any key to continue . . .



.
//straray.cpp
#include <iostream.h>
const int days=7;
const int max=10;
void main()
{
char star[days][max]={, ,
, ,
, ,
};
for (int j=0; j<days; j++)
cout << star[j] << endl; }


#include <iostream>
using namespace std;
int main(){
string str = "Hulagu Khan, (1218-1265), was a Mongol ruler who conquered
much of Western Asia. ";
char checkCharacter = 'o';
int count = 0;

for (int i = 0; i < str.size(); i++) {


if (str[i] == checkCharacter) { ++ count; } }
cout << "Number of " << checkCharacter << " = " << count;
return 0;}

:

Number of o = 5
--------------------------------
Process exited after 0.01816 seconds with return value 0
Press any key to continue . . .

:

Number of o = 5
--------------------------------
Process exited after 0.01816 seconds with return value 0
Press any key to continue . . .

1. ,
2. , 6- , , ,
,
3. U.CS101
4. he2must.blogspot.com
5. https://www.programiz.com/cpp-programming/strings
6. https://www.programiz.com/cpp-programming/examples/string-length

You might also like

  • Lecture 15
    Lecture 15
    Document40 pages
    Lecture 15
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 6
    Programming Lec 6
    Document51 pages
    Programming Lec 6
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lec1-1 Corporate Activity Shine
    Lec1-1 Corporate Activity Shine
    Document61 pages
    Lec1-1 Corporate Activity Shine
    Amarsaikhan Tuvshinbayar
    0% (1)
  • Lecture 13
    Lecture 13
    Document46 pages
    Lecture 13
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture - 10
    Lecture - 10
    Document35 pages
    Lecture - 10
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 9
    Lecture 9
    Document46 pages
    Lecture 9
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 8 2018
    Lecture 8 2018
    Document54 pages
    Lecture 8 2018
    Amarsaikhan Tuvshinbayar
    100% (3)
  • Lecture 12
    Lecture 12
    Document34 pages
    Lecture 12
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 5 2018
    Lecture 5 2018
    Document54 pages
    Lecture 5 2018
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture 3 2018
    Lecture 3 2018
    Document42 pages
    Lecture 3 2018
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 2 2018
    Lecture 2 2018
    Document33 pages
    Lecture 2 2018
    Amarsaikhan Tuvshinbayar
    100% (1)
  • Lecture 11
    Lecture 11
    Document24 pages
    Lecture 11
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture 6 2018
    Lecture 6 2018
    Document50 pages
    Lecture 6 2018
    Amarsaikhan Tuvshinbayar
    100% (3)
  • Lecture 4 2018
    Lecture 4 2018
    Document47 pages
    Lecture 4 2018
    Amarsaikhan Tuvshinbayar
    100% (4)
  • Lecture 7 20108
    Lecture 7 20108
    Document47 pages
    Lecture 7 20108
    Amarsaikhan Tuvshinbayar
    75% (4)
  • IT101 Lecture 4
    IT101 Lecture 4
    Document72 pages
    IT101 Lecture 4
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Baikal Hotolbor
    Baikal Hotolbor
    Document2 pages
    Baikal Hotolbor
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 3
    Lecture 3
    Document72 pages
    Lecture 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 1 2018
    Lecture 1 2018
    Document39 pages
    Lecture 1 2018
    Amarsaikhan Tuvshinbayar
    100% (6)
  • Baikal Hotolbor
    Baikal Hotolbor
    Document2 pages
    Baikal Hotolbor
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 4
    Programming Lec 4
    Document39 pages
    Programming Lec 4
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 9
    Programming Lec 9
    Document39 pages
    Programming Lec 9
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 7
    Programming Lec 7
    Document57 pages
    Programming Lec 7
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 3
    Lecture 3
    Document72 pages
    Lecture 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 2
    Lecture 2
    Document80 pages
    Lecture 2
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 1
    Lecture 1
    Document54 pages
    Lecture 1
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Programming Lec 8
    Programming Lec 8
    Document32 pages
    Programming Lec 8
    Amarsaikhan Tuvshinbayar
    100% (1)
  • Programming Lec 6
    Programming Lec 6
    Document51 pages
    Programming Lec 6
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • PL - 3
    PL - 3
    Document47 pages
    PL - 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Koosen 2018 Algorithm Programming 3
    Koosen 2018 Algorithm Programming 3
    Document46 pages
    Koosen 2018 Algorithm Programming 3
    Amarsaikhan Tuvshinbayar
    100% (1)