Académique Documents
Professionnel Documents
Culture Documents
-6 , ,
: . //
.
.
www.emust.edu.mn
float, int, char .
. , , .
,
.
C++- .
.
.
. .
C++- .
OOP- . Basic
Pascal (record) .
.
,
, ,
.
, .
//parts.cpp part part1;
#include <iostream>
using namespace std; part1.partnum=6244;
struct part part1.modelnum=373;
{ part1.cost=217.55;
int partnum;
int modelnum; cout <<"dugaar"<< part1.partnum<<endl;
float cost; cout <<"zagvar"<< part1.modelnum<<endl;
}; cout <<"une"<< part1.cost<<endl;
int main() }
{
:
6244,
373,
217.55
3 . 1- , 2-
, .
struct part
{
int partnum;
int modelnum;
float cost;
};
. Struct
. . 3
.
( ; )
.
( .).
part part1;
part part1 .
. ? 3
.
2 , 4 , 8 .
struct
C++- . .. struct part part1
.
. .
part1.partnum=6244;
, ( . ),
3 . part1- partnum .
,
.
.
.
, .
, 2
. .
.
struct Distance{
int feet;
float inch;
}d1 , d2, sum;
int main()
{
cout << "Enter 1st distance," << endl;
cout << "Enter feet: ";
cin >> d1.feet;
cout << "Enter inch: ";
cin >> d1.inch;
cout << "\nEnter information for 2nd distance" << endl;
cout << "Enter feet: ";
cin >> d2.feet;
cout << "Enter inch: ";
cin >> d2.inch;
sum.feet = d1.feet+d2.feet;
sum.inch = d1.inch+d2.inch;
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main() {
struct Books Book1; // Declare Book1 of type Book
struct Books Book2; // Declare Book2 of type Book
// book 1 specification
strcpy( Book1.title, "Programchlal");
strcpy( Book1.author, "A.Tuvshinbayar");
strcpy( Book1.subject, "C++ Programchlal");
Book1.book_id = 6495407;
// book 2 specification
strcpy( Book2.title, "Algorithm");
strcpy( Book2.author, "A.Tuvshinbayar");
strcpy( Book2.subject, "Flowgorithm");
Book2.book_id = 6495700;
// Print Book1 info
cout << "Book 1 title : " << Book1.title <<endl;
cout << "Book 1 author : " << Book1.author <<endl;
cout << "Book 1 subject : " << Book1.subject <<endl;
cout << "Book 1 id : " << Book1.book_id <<endl;
return 0;
}
.
#include <iostream>
#include <cstring>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main() {
struct Books Book1; // Declare Book1 of type Book
struct Books Book2; // Declare Book2 of type Book
// book 1 specification
strcpy( Book1.title, "Algorithm Programchlal");
strcpy( Book1.author, "R.Turbat");
strcpy( Book1.subject, "C++ Programming");
Book1.book_id = 6495407;
// book 2 specification
strcpy( Book2.title, "Algorithm Programchlal");
strcpy( Book2.author, "A.Tuvshinbayar");
strcpy( Book2.subject, "Telecom");
Book2.book_id = 6495700;
// Print Book1 info
printBook( Book1 );
return 0;
}
void printBook( struct Books book ) {
cout << "Book title : " << book.title <<endl;
cout << "Book author : " << book.author <<endl;
cout << "Book subject : " << book.subject <<endl;
cout << "Book id : " << book.book_id <<endl;
}
.
.
Room distance .
. distance
{13, 6.5} , distance {10, 0.0}
.
.
. Cardsharp 3
, .
. .
struct card
{
int number;
int suit;
}
2- 14 . 11- 14
, , , . 0- 3
. , , , .
const int clubs=0; //
const int diamonds=1; //
const int hearts=2; //
const int spades=3; //
struct card
{
int number;
int suit;
}
.
7
2
3
1- 3-
2- 3-
1- 2-
? (1,2,3) 3
. .
.
.
.
. ,
. 1- 3-, 3- 2-, 2- 1- .
,
, .
.
.
.
. Pascal
.
. .
#include <iostream>
using namespace std;
int main()
{
week today;
today = Wednesday;
cout << "Day " << today+1;
return 0;
}
day 4
.
.
0, 1 . Sun
0, Sat 6 . today+1 .
.
#include <iostream>
using namespace std;
enum season
{ spring = 0,
summer = 4,
autumn = 8,
winter = 12
};
int main()
{
season odoo;
odoo= summer;
cout << "zun " <<odoo<<"sar urgeljilne";
return 0;
}
Zun 4 sar urgeljilne
.
#include <iostream>
using namespace std;
int main() {
seasons s;
s = summer;
cout << "Summer = " << s << endl;
return 0;
}
Summer=4
C++-
. .
chcount .
space ( )
. .
// Computes time difference of two time period
// Time periods are entered by the user
#include <iostream>
using namespace std;
struct TIME
{
int seconds;
int minutes;
int hours;
};
int main()
{
struct TIME t1, t2, difference;
cout << endl << "TIME DIFFERENCE: " << t1.hours << ":" << t1.minutes << ":"
<< t1.seconds;
cout << " - " << t2.hours << ":" << t2.minutes << ":" << t2.seconds;
cout << " = " << difference.hours << ":" << difference.minutes << ":" <<
difference.seconds;
return 0;
}
void computeTimeDifference(struct TIME t1, struct TIME t2, struct TIME
*difference){
//cardenum.cpp
#include <iostream.h>
struct card
0 .
, 0- .
day1.suit=hearts;
cout << day1.suit;
hearts , 3 .