[学习笔记]C++学习第12天
```# include <iostream>
# include <iomanip>
# include <vector>
//c++17
using namespace std;
int main()
{
vector<unsigned int> product_id;
vector<int> product_num;
vector<double> product_price;
vector<double> product_cost;
cout << "Please enter id num price cost (Ctrl-D退出):";
int id, num;
double price;
while(cin >> id >> num >> price)
{
product_id.push_back(id);
product_num.push_back(num);
product_price.push_back(price);
product_cost.push_back(price*num);
cout << "Please enter id num price cost (Ctrl-D退出):";
}
cout << setw(8) << "产品" << " |" << setw(8) << "数量" << " |" << setw(8) << "单价" << " |" << setw(8) << "成本" << endl;
for(size_t i{} ; i!= product_id.size(); ++i)
{
cout << setw(8) << product_id << " |" ;
cout << setw(8) << product_num << " |" ;
cout << setw(8) << product_price << " |" ;
cout << setw(8) << product_cost << " |" ;
cout << endl;
}
}
```
本帖最后由 mdl2999_52pj 于 2021-6-1 13:59 编辑
```
# include <iostream>
# include <array>
//c++17
using namespace std;
int main()
{
const char *pstars[]{
"Fatty Arbuckle",
"Calara Bow",
"Lassie",
"Slim Pickens",
"Boris Karloff"
};
cout << "Enter a luck start! Enter a number between 1 and" << size(pstars) << endl;
size_t choice;
cin>> choice;
if (choice <1 and choice > size(pstars))
{
cout << "Sorry, yout don't have a lucky star!" << endl;
}
else
{
cout << "Your luck star is " << pstars << endl;
}
}
```
楼主加油 一起学习。。。C ++ 加油!!! ```
# include <iostream>
# include <iomanip>
//c++17
using namespace std;
int main()
{
//寻找质数
const size_t max{100};
long primes{2L};
size_t count{1};
long trial{3L};
while(count < max)
{
bool isprime {true};
for(size_t i{}; i!=count && isprime; ++i)
{
isprime = trial % primes > 0;
}
if (isprime)
{
primes = trial;
}
trial += 2;
}
cout << "The first " << max << " primes are: " << endl;
for(size_t i{}; i!=max; ++i)
{
cout << setw(7) << primes;
if ((i+1)%10==0)
{
cout << endl;
}
}
cout << endl;
}
```
```
# include <iostream>
# include <iomanip>
//c++17
using namespace std;
int main()
{
//寻找质数
const size_t max{100};
long primes{2L};
size_t count{1};
long trial{3L};
while(count < max)
{
bool isprime {true};
for(size_t i{}; i!=count && isprime; ++i)
{
isprime = trial % *(primes+i) > 0;
}
if (isprime)
{
*(primes+count++)= trial;
}
trial += 2;
}
cout << "The first " << max << " primes are: " << endl;
for(size_t i{}; i!=max; ++i)
{
cout << setw(7) << *(primes+i) ;
if ((i+1)%10==0)
{
cout << endl;
}
}
cout << endl;
}
```
学得挺好啊,楼主加油!
页:
[1]