-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// CPP Program to Print Fibonacci Number Series | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num = 7, i, current; | ||
int last = 0, prev = 1; | ||
cout << "Fibonacci Series : "; | ||
|
||
for(i = 1; i <= num; i = i + 1){ | ||
cout << last << "\t"; | ||
current = last + prev; | ||
last = prev; | ||
prev = current; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// CPP Program to check whether the year entered is Leap Year or not. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int year; | ||
cout<<"Enter a Year : "; | ||
cin>>year; | ||
|
||
if((year % 400 == 0) && (year % 4 == 0 || year % 100 != 100)){ | ||
cout<<"Year "<< year << " is a Leap Year"; | ||
} else { | ||
cout<<"Year "<< year <<" is not a Leap Year"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// CPP Program to demonstrate Classes and Objects. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
class System{ | ||
|
||
public: | ||
int sys_no; | ||
string System_name; | ||
}; | ||
|
||
int main(){ | ||
|
||
System sys1; | ||
sys1.sys_no = 01; | ||
sys1.System_name = "HP System 01"; | ||
|
||
cout<<sys1.sys_no<<endl; | ||
cout<<sys1.System_name<<endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// CPP Program to check entered number is prime or not. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num; | ||
cout << "Enter a Number : "; | ||
// Taking input from the User | ||
cin >> num; | ||
|
||
if(num < 2) | ||
{ | ||
cout << "NOT PRIME"; | ||
return 0; | ||
} | ||
else | ||
{ | ||
for(int i = 2;i < num;i++) | ||
{ | ||
if(num % i == 0){ | ||
cout << "NOT PRIME"; | ||
return 0; | ||
} | ||
} | ||
cout << "PRIME"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// CPP Program to print the reversed number of entered number. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int num, ans = 0, rem; | ||
cout << "Enter a Number : "; | ||
// Taking input from User | ||
cin >> num; | ||
|
||
while(num > 0){ | ||
rem = num % 10; | ||
num /= 10; | ||
|
||
ans = ans * 10 + rem; | ||
} | ||
cout << "Reverse of entered number is : " << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// CPP Program to store the information of 10 Students using Object arrays in CPP Classes. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Declaring a student class | ||
class Student { | ||
public: | ||
int rollNumber; | ||
float marks; | ||
|
||
void setInfo(int rollNumber, float marks){ | ||
this -> rollNumber = rollNumber; | ||
this -> marks = marks; | ||
} | ||
|
||
void displayInfo() { | ||
cout << "Roll Number : " << rollNumber << endl; | ||
cout << "Marks : " << marks << endl; | ||
} | ||
}; | ||
|
||
int main(){ | ||
|
||
Student students[10]; | ||
|
||
for(int i = 0; i < 10;i = i + 1){ | ||
string name; | ||
int rollNumber; | ||
float marks; | ||
|
||
cout << "Enter information for student: "<< (i + 1) << ":" << endl; | ||
cout << "Roll Number: "; | ||
cin >> rollNumber; | ||
cout << "Marks: "; | ||
cin >> marks; | ||
|
||
students[i].setInfo(rollNumber, marks); | ||
} | ||
|
||
cout << "Information of all Students: "<<endl; | ||
for(int i = 0; i < 10; i = i + 1){ | ||
students[i].displayInfo(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// CPP Program to find the factorial of entered number. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int num, i , fact = 1; | ||
cout << "Enter a Number: "; | ||
// Taking input from User | ||
cin >> num; | ||
|
||
if(num == 0){ | ||
cout << "The factorial of 0 is 1"<<endl; | ||
} | ||
else if(num < 0){ | ||
cout << "Please Enter a Number that is greater than or equal to 0"<<endl; | ||
} else{ | ||
for(i = 1; i <= num; i = i + 1){ | ||
fact *= i; | ||
} | ||
cout << "The factorial of "<< num << " is : "<< fact<<endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
bool isPrime(int number) { | ||
if (number < 2) { | ||
return false; | ||
} else { | ||
for (int i = 2; i * i <= number; i++) { | ||
if (number % i == 0) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void displayPrimes(int number) { | ||
for (int i = 2; i <= number; i++) { | ||
if (isPrime(i)) { | ||
cout << i << " "; | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
int num; | ||
cout << "Enter a number up to which you want to print the prime number series: "; | ||
cin >> num; | ||
displayPrimes(num); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
class Car { | ||
public: | ||
string brand; | ||
string model; | ||
// Default constructor | ||
Car(string brand, string model){ | ||
cout << brand <<" " << model << endl; | ||
} | ||
}; | ||
|
||
int main () { | ||
|
||
Car One("BMW","X5"); | ||
Car Two("Ford","Mustang"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int add (int a, int b) { | ||
return a + b; | ||
} | ||
|
||
double add (double a, double b) { | ||
return a + b; | ||
} | ||
|
||
int main () { | ||
|
||
int sum1 = add (3,4); | ||
double sum2 = add (3.3,4.4); | ||
|
||
cout << "Sum of Integers: " << sum1 << endl; | ||
cout << "Sum of doubles: " << sum2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
class ComplexNum { | ||
private: | ||
int real, imag; | ||
public: | ||
ComplexNum(int r = 0, int i = 0){ | ||
real = r; | ||
imag = i; | ||
} | ||
|
||
ComplexNum operator+ (ComplexNum const& obj){ | ||
ComplexNum res; | ||
res.real = real + obj.real; | ||
res.imag = imag + obj.imag; | ||
return res; | ||
} | ||
void print() { | ||
cout << real << " + i"<< imag << endl; | ||
} | ||
}; | ||
|
||
int main() { | ||
|
||
ComplexNum c1(10, 5), c2(2, 4); | ||
|
||
ComplexNum c3 = c1 + c2; | ||
c3.print(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
int N; | ||
cout << "Enter the number of Persons : "; | ||
cin >> N; | ||
|
||
struct { | ||
string firstName, lastName; | ||
int age; | ||
} Person[N]; | ||
|
||
// info lene ke liye loop | ||
for(int i = 0; i < N; i++){ | ||
cout <<"\nEnter details of Person " << i + 1 << ":\n"; | ||
cout << "Enter First Name: "; | ||
cin >> Person[i].firstName; | ||
cout << "Enter Last Name: "; | ||
cin >> Person[i].lastName; | ||
cout << "Enter the Age: "; | ||
cin >> Person[i].age; | ||
} | ||
|
||
int eldestAge = 0; | ||
for (int i = 1; i < N; i++) { | ||
if(Person[i].age > Person[eldestAge].age){ | ||
eldestAge = i; | ||
} | ||
} | ||
|
||
cout << "\n The eldest person is: \n"; | ||
cout << "Name: " << Person[eldestAge].firstName << + " " << Person[eldestAge].lastName << endl; | ||
cout << "Age: " << Person[eldestAge].age << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
int N; | ||
cout << "Enter the number of employees : "; | ||
cin >> N; | ||
|
||
struct { | ||
string firstName, lastName; | ||
float basicSalary, deduction, netSalary; | ||
} employees[N]; | ||
|
||
for (int i = 0; i < N; i++){ | ||
cout << "\nEnter details of employee " << i+1 << ":\n"; | ||
cout << "Enter First Name: "; | ||
cin >> employees[i].firstName; | ||
cout << "Enter Last Name: "; | ||
cin >> employees[i].lastName; | ||
cout << "Basic Salary: "; | ||
cin >> employees[i].basicSalary; | ||
cout << "Deductions: "; | ||
cin >> employees[i].deduction; | ||
|
||
// net salary calculate krne ke liye | ||
// net salary = basis salary - deductions | ||
employees[i].netSalary = employees[i].basicSalary - employees[i].deduction; | ||
} | ||
|
||
|
||
for (int i = 0; i < N; i++) { | ||
cout << "\n\n\nDetails of employee " << i+1 << ":\n"; | ||
cout << "Name: " << employees[i].firstName << "" << + " " << employees[i].lastName << "\n"; | ||
cout << "Net Salary: " << employees[i].netSalary << "\n"; | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
|
||
|
||
int *s = new int; | ||
|
||
*s = 32; | ||
|
||
cout << "Value of s is " << *s << endl; | ||
cout << "Memory location is " << &s << endl; | ||
|
||
delete s; | ||
return 0; | ||
} |
Oops, something went wrong.