1. 如何使用cout在C++的代码里面:
outputs:
the codes:
// c++ for beginner
/* what is C++ (general purpose, complied and case-sensitive)
C++ understandable and easy to use, fast execution of demanding
tasks. the source codes need to be complied into machine code
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
std::cout << "Hello, world!" << std::endl;
std::cout << "my name is saldina.\n";
std::cout << "today is tuesday." << std::endl;
return 0;
}
what is the variable? what is the datatypes?
// c++ for beginner
/* what is variable? variable is just like a container
and you could store some data types.
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
float annualSalary = 50000.99;
float monthlySalary = annualSalary / 12;
std::cout << "your monthly salary is " << monthlySalary << std::endl;
return 0;
}
what is the function of cin:
// c++ for beginner
/* what is variable? variable is just like a container
and you could store some data types.
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
// float annualSalary = 50000.99;
float annualSalary;
std::cout << "please enter your annual salary" << std::endl;
std:: cin >> annualSalary;
float monthlySalary = annualSalary / 12;
std::cout << "your monthly salary is " << monthlySalary << std::endl;
std::cout << "in 10 years , you will earn:" << annualSalary*10 << std::endl;
return 0;
}
The kinds of all variables :
the size of int is 4bytes
int min value is -2147483648
int max value is 2147483647
The corresponding codes:
// c++ for beginner
/* what is variable? variable is just like a container
and you could store some data types.
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
int yearOfBirth = 1995;
char gender = 'f';
bool isOlderThan18 = true;
float averageGrade = 4.5;
double balance = 45165453646;
std::cout << "the size of int is " << sizeof(int) << "bytes" << std::endl;
std::cout << "int min value is " << INT_MIN << std::endl;
std::cout << "int max value is " << INT_MAX << std::endl;
return 0;
}
the outputs:
The correspongding codes:
// c++ for beginner
/* what is variable? variable is just like a container
and you could store some data types.
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
int yearOfBirth = 1995;
char gender = 'f';
bool isOlderThan18 = true;
float averageGrade = 4.5;
double balance = 45165453646;
std::cout << "the size of int is " << sizeof(int) << "bytes" << std::endl;
std::cout << "int min value is " << INT_MIN << std::endl;
std::cout << "int max value is " << INT_MAX << std::endl;
std::cout << "UInt max value is " << UINT_MAX << std::endl;
std::cout << "the size of unsigned int is " << sizeof(unsigned int) << "bytes" << std::endl;
std::cout << "the size of char is " << sizeof(char) << "bytes\n";
std::cout << "the size of float is " << sizeof(float) << "bytes" << std::endl;
std::cout << "the size of double is " << sizeof(double) << "bytes" << std::endl;
return 0;
}