Skip to content

Commit 993fa54

Browse files
committed
first_cpp_commit
1 parent f763a4b commit 993fa54

13 files changed

+239
-0
lines changed

eighth.exe

129 KB
Binary file not shown.

eighth_cpp_file.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<iostream>
2+
3+
int main()
4+
{
5+
6+
std::string name;
7+
int age;
8+
9+
std::cin>>age;
10+
11+
//to get input with space we will use
12+
std::cout<<"Enter your full name: ";
13+
std::getline(std::cin>>std::ws,name);
14+
15+
std::cout<<'\n'<<"Enter your age: ";
16+
17+
18+
std::cout<<'\n'<<"Hi "<<name<<" your age is "<<age;
19+
20+
//note if we use getline() after cin it by default accepts a newline char and to avoid this we can use std::ws this will clear any newline char or white space after cin
21+
return 0;
22+
}

fifth_cpp_file.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
3+
//'typedef' keyword is used when we want to reduse typos like whem we want to call one data type with other name,we inclued _t st hte end of the new name to recognize typedef this additional name is called alias
4+
//this can also be done by using key word and that is more preferable as it hels in creating templates more efficiently
5+
typedef std::string string_t;
6+
7+
using num_t = int;
8+
9+
int main()
10+
{
11+
string_t a = "Hi there";
12+
num_t r = 1;
13+
return 0;
14+
}

first_cpp_file.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
//it is a basic heaser file which contain info about the basic input output operations
3+
4+
int main()
5+
{
6+
std::cout<<"i like science"<<'\n'<<std::endl;
7+
std::cout << "science is cool" <<'\n';
8+
return 0;
9+
}

forth_cpp_file.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
3+
4+
// creating a namespace
5+
//they are used to avoid naming conflicts like we want to use diffrent values of same variable x but we cannot decleare x 2 times directly so we use namespace
6+
7+
/*
8+
Note -:
9+
if we use x from namespace first we have to write first::x
10+
if we are usin x form namespace second we have to write second::xor
11+
12+
if we didnt mentioned any thing it will use x decllarend in the main
13+
14+
if we wrote
15+
using namespace first
16+
17+
default value of x will be from namespace first and we have to mention if we use it from secdond and viseversa
18+
*/
19+
20+
namespace first
21+
{
22+
int x = 2;
23+
}
24+
namespace second
25+
{
26+
int x = 3;
27+
}
28+
29+
int main()
30+
{
31+
using namespace first;
32+
33+
34+
std::cout<<x;
35+
return 0;
36+
}

forth_cpp_file.exe

128 KB
Binary file not shown.

hybotanious_problem.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <cmath>
3+
4+
5+
int main()
6+
{
7+
float base,perpendicular,hypotanious;
8+
9+
//base input
10+
std::cout<<"Enter the length of base for the right triangle: ";
11+
std::cin>>base;
12+
13+
//perpendicular
14+
std::cout<<'\n'<<"Enter the length of perpendicular for the right triangle: ";
15+
std::cin>>perpendicular;
16+
17+
hypotanious = sqrt(pow(base,2)+pow(perpendicular,2));
18+
19+
std::cout<<'\n'<<"Enter value for the hypotanious length is: "<<hypotanious;
20+
21+
return 0;
22+
}

ninth_cpp_file.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
#include<cmath>
3+
4+
5+
int main()
6+
{
7+
//some useful math related functions
8+
double a = 3;
9+
double b = 4;
10+
double z;
11+
z = std::max(a,b); // to get max of two numbers
12+
z = std::min(a,b); // to get min of two numbers
13+
z = pow(a,b); // a to the power of b
14+
z = sqrt(a); //square root of a
15+
z = abs(-3); //modlus function
16+
z = round(3.14); // return rounded value (not the floor or ceiling)
17+
z = ceil(3.14); //return ceiling value 4 here
18+
z = floor(3.14); //return the floor value 3 here
19+
20+
//Note -: there are many more functions in cmath
21+
22+
23+
return 0;
24+
}

second_cpp_file.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<iostream>
2+
3+
int main()
4+
{
5+
/*
6+
variables: they are the containers which are small chunks of the memory and each variable cossisponds to a specific memory loocation
7+
8+
the dype of data stored in the variable depends on the data type of the variable
9+
*/
10+
11+
//we can create variables in two ways
12+
13+
//way 1 ->
14+
//declaration
15+
int a;
16+
//assignment
17+
a = 4;
18+
19+
//way 2 ->
20+
//declaration with assignment
21+
22+
int b = 4;
23+
24+
/*
25+
there are several basic datatypes -:
26+
27+
int :: fo integer value
28+
double , float :: for real numbers or numbers with decimals
29+
char :: for characters
30+
string :: to store sequence of text ,like sentences ,words,paragraphs
31+
bool :: to store true or false
32+
33+
not string is avilable in std namespace
34+
*/
35+
36+
int a = -1;
37+
float b = 45.6;
38+
double c = 65.4;
39+
char d = '\n';
40+
std::string e = "science is all about exploration";
41+
bool f = true;
42+
43+
std::cout <<a<<b<<c<<d<<e<<f<<std::endl;
44+
45+
46+
return 0;
47+
}

seventh.exe

128 KB
Binary file not shown.

seventh_cpp_file.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
/*
6+
there are two types of type conversions possible
7+
8+
inplesit and explesit
9+
10+
implesit happen by their own while in explecit we need to specify
11+
12+
explesit conversion can be very usefu in integer division
13+
*/
14+
15+
int number_of_apples = 10;
16+
int number_of_people = 11;
17+
18+
float apple_per_person = number_of_apples/number_of_people;
19+
20+
// here the result is not what which is expected and the reason for thsi is when integer is divvided by integer it gives an integer so we have t o type cast that integer to float in order to obtain a decimal value;
21+
22+
float apple_per_eater = number_of_apples/(float)number_of_people ;
23+
24+
std::cout<<apple_per_person<<'\n'<<apple_per_eater;
25+
26+
return 0;
27+
}

sixth_cpp_file.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<iostream>
2+
//arithmatic operators
3+
4+
int main()
5+
{
6+
int students = 1;
7+
students+=1;
8+
students -= 1;
9+
students *=2;
10+
students /= 1;
11+
12+
std::cout<<students;
13+
14+
students++;
15+
students--;
16+
17+
students = 3+4-4*5/6;
18+
19+
return 0;
20+
}

third_cpp_file.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
//we can create constants with "const" key word before declearing a data type of the variable , as a convention we use uppercamelcase for their naming
6+
7+
//calculating area of the circle
8+
9+
const float PI = 3.14;
10+
float radius = 23;
11+
12+
float area = PI*radius*radius;
13+
14+
std::cout<<"Area of the circle is: "<<area<<std::endl;
15+
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)