Escolar Documentos
Profissional Documentos
Cultura Documentos
Programação
Prof. Walter Aoiama Nagai
walternagai@unifei.edu.br
mas antes, abra o Replit...
Tipos primitivos
● char #include <iostream>
using namespace std;
● int
● float int main() {
char letra = 97;
● double cout << letra << endl;
● bool letra = 'b';
cout << letra << endl;
Modificadores return 0;
}
● short, long, unsigned,
signed
Tipos primitivos
● char #include <iostream>
using namespace std;
● int
● float int main() {
int x = 3, y = 5;
● double
● bool cout << x + y << endl;
return 0;
Modificadores }
int main() {
int x;
float y;
y = 3.14159;
x = y;
return 0;
}
Conversão de tipos >> Alargamento
#include <iostream>
using namespace std;
int main() {
int x;
float y;
x = 3;
y = x + 0.14159;
return 0;
}
Conversão de tipos >> Cast
#include <iostream>
using namespace std;
int main() {
WeekDay weekday;
weekday = thursday;
cout << weekday << endl;
weekday = (WeekDay) 1;
cout << weekday << endl;
return 0;
}
Criando seu próprio tipo de dados
#include <iostream>
using namespace std;
int main() {
ulong inteiroLongo = 2415677;
meubool mVariavel = FALSO;
return 0;
}
Criando seu próprio tipo de dados
#include <iostream>
using namespace std;
int main() {
WeekDay weekday;
weekday = thursday;
cout << weekday << endl;
weekday = monday;
cout << weekday << endl;
return 0;
}
Tipo string
#include <iostream>
using namespace std;
int main() {
string nome, mensagemcurta;
cout << nome << ", " << mensagemcurta << endl;
return 0;
}
Formatando a saída do cout...
Comando setw
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// formata o número com espaços em branco
// e alinhados a direita
cout << setw(10) << 123 << endl;
cout << setw(10) << 123456<< endl;
cout << setw(10) << 123456789 << endl;
return 0;
}
Comando setfill
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// troca os espaços em branco por um caracter
return 0;
}
Comando setprecision
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
#include <cmath>
using namespace std;
int main () {
double f = M_PI;
// precisão considerando o ponto decimal
cout << setprecision(5) << f << '\n';
cout << setprecision(9) << f << '\n';
// precisão desconsiderando o ponto decimal
cout << fixed;
cout << setprecision(5) << f << '\n';
cout << setprecision(9) << f << '\n';
return 0;
}
Comandos setfill, setw e setprecision
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
#include <cmath>
using namespace std;
int main () {
double f = M_PI;
cout << setfill('0') << setw(12) << setprecision(5) << f << '\n';
cout << setfill('0') << setw(12) << setprecision(9) << f << '\n';
cout << fixed;
cout << setfill('0') << setw(12) << setprecision(5) << f << '\n';
cout << setfill('0') << setw(12) << setprecision(9) << f << '\n';
return 0;
}
Até a próxima aula!