Professional Documents
Culture Documents
Programming Lec 11
Programming Lec 11
-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;
}
--------------------------------
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;
}
:
#include <iostream>
using namespace std;
int main()
{
char str[100];
cout << "Temdegt moroo oruul: ";
cin.get(str, 100);
--------------------------------
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;
}
:
,
. ..
15 25 35
int main()
{
const int max=80;
char str[max];
cout << "\n Mor oruulj ogno uu: ";
cin.get(str, max);
cout << "Oruulsan mor: "<< str;
}
:
? 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;
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