-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
125 lines (101 loc) · 2.6 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
void classicOutput();
void classicInput();
void sqrX();
#include <iostream>
void streamOutput();
void streamInput();
using namespace std;
int main()
{
//classicOutput();
//sqrX();
//classicInput();
//streamOutput();
//streamInput();
return 0;
}
void classicOutput()
{
//preview
printf("Hello, world!");
double pi = 3.1415926;
printf("Pi = [%5.2lf]", pi);
//control characters
printf("\nNext line");
printf("\n\tTab & next line");
printf("\n\vVerticat tab");
printf("\nSome text");
printf("\bT");
printf("\b\bXT");
//printf("\b\b\bEXT");
//printf("\b\b\b\bTEXT");
printf("\nSome another text");
printf("\rHA! ");
printf("\nHmm..\a");
//formats
int x = 15;
printf("\nx = %d //dec", x);
printf("\nx = %x //hex", x); //trouble with tabulation (!) %2x
printf("\nx = %o //oct", x);
float big_pi = 314159.26;
printf("\nPi = %f", big_pi);
printf("\nPi = %e", big_pi);
char a = 'a';
printf("\n%c", a);
}
#include <math.h>
void sqrX()
{
double x = 0;
double y = 0;
for (x = 0; x < 10; x+=0.5) {
y = x*x;
printf("| x = %lf | y = %lf | \n", x, y);
//looks pretty terrible
}
}
void classicInput()
{
char name[32];
printf(" Hey, what is your name?\n > ");
scanf("%s", name);
printf(" Hi, %s! Welcome!\n", name);
printf(" Tell me about your age and iq, please!\n > ");
int age = 0;
int iq = 0;
scanf("%d%d", &age, &iq);
printf(" Wow! You are sooo young my %d-years old friend, but already very intelligent!\n", age);
printf(" %d iq point is great!\n", iq);
}
#include <iomanip>
void streamOutput()
{
//preview
cout << "Hello, world!";
double pi = 3.1415926;
cout << pi << endl;
//controls
cout << "Next line" << endl << "now";
cout << "\n\t Tab & next character is working too";
//formats
int x = 15;
cout << endl << "x = " << dec << x;
cout << endl << "x = " << hex << setw(2) << x; //trouble with tabulation (!) setw(2)
cout << endl << "x = " << oct << x;
char a = 'a';
cout << endl << a;
}
void streamInput()
{
char name[32];
cout << " Hey, what is your name?" << endl << " > ";
cin >> name;
cout << " Hi, " << name << " Welcome!" << endl;
cout << " Tell me about your age and iq, please!" << endl << " > ";
int age = 0;
int iq = 0;
cin >> age >> iq;
cout << " Wow! You are sooo young my " << age << "-years old friend, but already very intelligent!" << endl;
cout << " " << iq << " iq point is great!" << endl;
}