Skip to content

Commit 81a10e8

Browse files
committed
Add more examples files
1 parent fc48adf commit 81a10e8

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

code.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
/**
7+
8+
We start with a code made only with 0's and 1's. In the code, each sequence
9+
of 1's means to be a number depending on the length of the sequence.
10+
For instance, 011101100001 would have the numbers 3, 2 and 1.
11+
12+
At this point, we have to multiply each number to obtain a final number.
13+
14+
*/
15+
16+
int main()
17+
{
18+
cout <<"Enter the code:"<<endl;
19+
string code ;
20+
getline(cin,code);
21+
22+
int one_count = 0;
23+
int finalNumber = 1;
24+
25+
for(int i=0; i<code.size(); ++i)
26+
{
27+
switch(code.at(i))
28+
{
29+
case '0':
30+
{
31+
if(one_count > 0)
32+
{
33+
finalNumber *= one_count ;
34+
one_count = 0;
35+
}
36+
}break;
37+
38+
case '1':
39+
{
40+
one_count ++ ;
41+
}break;
42+
}
43+
}
44+
45+
cout << "Cabalistic Number: " << finalNumber << endl;
46+
}

delet_blank_spaces.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
/**
7+
This code erase blank spaces of a statement given by the user.
8+
After that, mentions the count of blank spaces that have been erased.
9+
*/
10+
11+
int main()
12+
{
13+
string s;
14+
cout << "DELETE BLANK SPACES" << endl;
15+
cout << "Input a phrase: " ;
16+
getline(cin,s); // read one line
17+
cout << endl;
18+
19+
int tmn = s.size(); // save the length of the string
20+
int blank_count = 0;
21+
22+
for(int a=0; a<s.size(); a++)
23+
if( s.at(a)==' ' )
24+
{
25+
s.erase(a,1);
26+
blank_count ++ ;
27+
}
28+
29+
cout<<s<<endl;
30+
cout << "Deleted blank spaces: " << blank_count << endl;
31+
cout<<endl;
32+
}

game.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include<iostream>
2+
#include<ctime>
3+
#include<cstdlib>
4+
using namespace std;
5+
int main()
6+
{
7+
int n, x;
8+
int a;
9+
bool cerrar=true;
10+
srand(time(0));
11+
12+
do
13+
{
14+
cout<<"\t+++++ GUESS +++++"<<endl<<endl;
15+
cout<<"\t- 1. Play\n";
16+
cout<<"\t- 2. Exit\n"<<endl<<endl;
17+
cout<<"\t- Choose an option: ";
18+
cin>>a;
19+
cout<<endl;
20+
21+
switch(a)
22+
{
23+
case 1:
24+
cout<<"Set a max number: ";
25+
int max;
26+
cin>>max;
27+
28+
n=rand()%max+1;
29+
30+
cout<<endl;
31+
cout<<"I've thought a number. Do you know what is it?" <<endl;
32+
33+
do{
34+
cin>>x;
35+
36+
if(x>n)
37+
cout<<"Incorrect. Number is smaller\n";
38+
if(x<n)
39+
cout<<"Incorrect. Number is bigger\n";
40+
if(x==n)
41+
cout<<"GOTCHA!"<<endl;
42+
43+
cout<<endl;
44+
}while(x!=n);
45+
46+
break;
47+
48+
case 2:
49+
cerrar=false;
50+
break;
51+
52+
default:
53+
cout<<"Opcion no valida"<<endl;
54+
cout<<endl;
55+
}
56+
57+
}while(cerrar==true);
58+
}

vector_sort.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <cstdlib>
4+
#include <algorithm> // std::sort
5+
6+
using namespace std;
7+
8+
void printMyVector (vector<int> &v)
9+
{
10+
for(int i=0; i<v.size();i++)
11+
cout<< v.at(i) << " ";
12+
}
13+
14+
int main()
15+
{
16+
int tmn;
17+
cout<<"Tell me a vector size: ";
18+
cin>>tmn;
19+
20+
vector<int> v(tmn); // create an empty vector
21+
int elem;
22+
23+
for(int i=0; i<v.size(); i++)
24+
{
25+
cout << "Give me an int number: ";
26+
cin >> elem;
27+
v.at(i) = elem;
28+
}
29+
30+
cout << endl;
31+
cout << "This is your vector:" << endl;
32+
printMyVector(v);
33+
cout << endl;
34+
35+
sort( v.begin(), v.end());
36+
37+
cout<<endl;
38+
cout<< "This is your sorted vector:"<< endl;
39+
printMyVector(v);
40+
cout << endl;
41+
}

0 commit comments

Comments
 (0)