From dca09b04475bf3c2a76bc055b817406f366334bf Mon Sep 17 00:00:00 2001 From: Himanshu Parihar <94682026+Pariharx7@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:10:38 +0530 Subject: [PATCH] Add files via upload --- downloads/01-Fibonacci.cpp | 18 ++++++++++++++ downloads/02-LeapYear.cpp | 17 +++++++++++++ downloads/03-SimpleClass.cpp | 21 ++++++++++++++++ downloads/04-PrimeNumber.cpp | 28 ++++++++++++++++++++++ downloads/05-Reverse.cpp | 20 ++++++++++++++++ downloads/06-ClassObjects.cpp | 45 +++++++++++++++++++++++++++++++++++ downloads/07-Factorial.cpp | 25 +++++++++++++++++++ downloads/08-PN-series.cpp | 32 +++++++++++++++++++++++++ downloads/09-constructor.cpp | 20 ++++++++++++++++ downloads/10-funOver.cpp | 21 ++++++++++++++++ downloads/11-operatorOver.cpp | 32 +++++++++++++++++++++++++ downloads/eldestPerson.cpp | 36 ++++++++++++++++++++++++++++ downloads/netsalary.cpp | 40 +++++++++++++++++++++++++++++++ downloads/new.cpp | 16 +++++++++++++ downloads/scopers.cpp | 16 +++++++++++++ 15 files changed, 387 insertions(+) create mode 100644 downloads/01-Fibonacci.cpp create mode 100644 downloads/02-LeapYear.cpp create mode 100644 downloads/03-SimpleClass.cpp create mode 100644 downloads/04-PrimeNumber.cpp create mode 100644 downloads/05-Reverse.cpp create mode 100644 downloads/06-ClassObjects.cpp create mode 100644 downloads/07-Factorial.cpp create mode 100644 downloads/08-PN-series.cpp create mode 100644 downloads/09-constructor.cpp create mode 100644 downloads/10-funOver.cpp create mode 100644 downloads/11-operatorOver.cpp create mode 100644 downloads/eldestPerson.cpp create mode 100644 downloads/netsalary.cpp create mode 100644 downloads/new.cpp create mode 100644 downloads/scopers.cpp diff --git a/downloads/01-Fibonacci.cpp b/downloads/01-Fibonacci.cpp new file mode 100644 index 0000000..246f1c1 --- /dev/null +++ b/downloads/01-Fibonacci.cpp @@ -0,0 +1,18 @@ +// CPP Program to Print Fibonacci Number Series +#include +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; +} diff --git a/downloads/02-LeapYear.cpp b/downloads/02-LeapYear.cpp new file mode 100644 index 0000000..4baf988 --- /dev/null +++ b/downloads/02-LeapYear.cpp @@ -0,0 +1,17 @@ +// CPP Program to check whether the year entered is Leap Year or not. +#include +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; +} diff --git a/downloads/03-SimpleClass.cpp b/downloads/03-SimpleClass.cpp new file mode 100644 index 0000000..410367f --- /dev/null +++ b/downloads/03-SimpleClass.cpp @@ -0,0 +1,21 @@ +// CPP Program to demonstrate Classes and Objects. +#include +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< +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"; + } +} diff --git a/downloads/05-Reverse.cpp b/downloads/05-Reverse.cpp new file mode 100644 index 0000000..414f654 --- /dev/null +++ b/downloads/05-Reverse.cpp @@ -0,0 +1,20 @@ +// CPP Program to print the reversed number of entered number. +#include +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; +} diff --git a/downloads/06-ClassObjects.cpp b/downloads/06-ClassObjects.cpp new file mode 100644 index 0000000..237b26f --- /dev/null +++ b/downloads/06-ClassObjects.cpp @@ -0,0 +1,45 @@ +// CPP Program to store the information of 10 Students using Object arrays in CPP Classes. +#include +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: "< +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"< +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; +} diff --git a/downloads/09-constructor.cpp b/downloads/09-constructor.cpp new file mode 100644 index 0000000..93b2dcc --- /dev/null +++ b/downloads/09-constructor.cpp @@ -0,0 +1,20 @@ +#include +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; +} \ No newline at end of file diff --git a/downloads/10-funOver.cpp b/downloads/10-funOver.cpp new file mode 100644 index 0000000..f6fa3d8 --- /dev/null +++ b/downloads/10-funOver.cpp @@ -0,0 +1,21 @@ +#include +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; +} \ No newline at end of file diff --git a/downloads/11-operatorOver.cpp b/downloads/11-operatorOver.cpp new file mode 100644 index 0000000..23d11d9 --- /dev/null +++ b/downloads/11-operatorOver.cpp @@ -0,0 +1,32 @@ +#include +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; +} diff --git a/downloads/eldestPerson.cpp b/downloads/eldestPerson.cpp new file mode 100644 index 0000000..80b407c --- /dev/null +++ b/downloads/eldestPerson.cpp @@ -0,0 +1,36 @@ +#include +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; +} \ No newline at end of file diff --git a/downloads/netsalary.cpp b/downloads/netsalary.cpp new file mode 100644 index 0000000..134a15f --- /dev/null +++ b/downloads/netsalary.cpp @@ -0,0 +1,40 @@ +#include +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; +} \ No newline at end of file diff --git a/downloads/new.cpp b/downloads/new.cpp new file mode 100644 index 0000000..67072e1 --- /dev/null +++ b/downloads/new.cpp @@ -0,0 +1,16 @@ +#include +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; +} \ No newline at end of file diff --git a/downloads/scopers.cpp b/downloads/scopers.cpp new file mode 100644 index 0000000..087706f --- /dev/null +++ b/downloads/scopers.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + + +class Data{ + public: + void info(); +}; + +void Data::info() {cout << "I got some data";} +int main(){ + Data data1; + data1.info(); + + return 0; +} \ No newline at end of file