0% found this document useful (0 votes)
49 views4 pages

CP Lesson1-2 Excerise and Tasks

The document contains code for several C++ programs that demonstrate basic concepts like input/output, mathematical functions, and expressions. The first program defines physical constants and gets user input to output age, name, department, and GPA. The second program gets a degree value and converts it to radians to calculate trigonometric functions. The third program gets a number and calculates various mathematical operations on it like square, cube, logarithms. The last program defines variables x and y, performs absolute value, power, square root and other operations on expressions involving them, and outputs the results.

Uploaded by

Saad tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views4 pages

CP Lesson1-2 Excerise and Tasks

The document contains code for several C++ programs that demonstrate basic concepts like input/output, mathematical functions, and expressions. The first program defines physical constants and gets user input to output age, name, department, and GPA. The second program gets a degree value and converts it to radians to calculate trigonometric functions. The third program gets a number and calculates various mathematical operations on it like square, cube, logarithms. The last program defines variables x and y, performs absolute value, power, square root and other operations on expressions involving them, and outputs the results.

Uploaded by

Saad tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LESSON 1 E1:

#include <string>

using namespace std;

int main() {

const double speedOfLight = 299792458; // meters per second

const double plancksConstant = 6.62607004e-34; // joule second

const double electronCharge = 1.60217662e-19; // coulombs

const double avogadrosNumber = 6.02214076e23; // per mole

int age;

string fullName;

string department;

double cgpa;

cout << "Enter your age: ";

cin >> age;

cout << "Enter your full name: ";

getline(cin >> ws, fullName);

cout << "Enter your department: ";

getline(cin >> ws, department);

cout << "Enter your CGPA: ";

cin >> cgpa;

cout << "Speed of light: " << speedOfLight << " m/s" << endl;

cout << "Planck's constant: " << plancksConstant << " J.s" << endl;

cout << "Charge on electron: " << electronCharge << " C" << endl;

cout << "Avogadro's number: " << avogadrosNumber << " /mol" << endl;

cout << "Age: " << age << endl;

cout << "Full name: " << fullName << endl;

cout << "Department: " << department << endl;

cout << "CGPA: " << cgpa << endl;

return 0; }
Lesson2 Task1:

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double angleInDegrees;

cout << "Enter an angle in degrees: ";

cin >> angleInDegrees;

double angleInRadians = angleInDegrees * M_PI / 180.0;

double cosine = cos(angleInRadians);

double sine = sin(angleInRadians);

double tangent = tan(angleInRadians);

cout << "cos(" << angleInDegrees << ") = " << cosine << endl;

cout << "sin(" << angleInDegrees << ") = " << sine << endl;

cout << "tan(" << angleInDegrees << ") = " << tangent << endl;

return 0;

}
Lesson 2 Task2

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double num;

cout << "Enter a floating-point number: ";

cin >> num;

//Assignment or Formulation

double square = pow(num, 2); double cube = pow(num, 3);

double squareRoot = sqrt(num); double floorValue = floor(num);

double truncateValue = trunc(num);

double ceilingValue = ceil(num);

double roundOffValue = round(num);

double naturalLog = log(num);

double base10Log = log10(num);

//Outputs

cout << "Square: " << square << endl;

cout << "Cube: " << cube << endl; cout << "Square root: " << squareRoot << endl;

cout << "Floor: " << floorValue << endl; cout << "Truncate: " << truncateValue << endl;

cout << "Ceiling: " << ceilingValue << endl;

cout << "Round off: " << roundOffValue << endl;

cout << "Natural log: " << naturalLog << endl;

cout << "Base 10 log: "<<base10Log<<endl;

return 0;

}
Lesson2 E1(EXPRESSIONS):

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double x, y;

cout << "Enter the value of x: ";

cin >> x;

cout << "Enter the value of y: ";

cin >> y;

double result1 = abs(x + y);

double result2 = abs(x) + abs(y);

double result3 = pow(x, 3) / y + y;

double result4 = sqrt(pow(x, 6) + pow(y, 5));

double result5 = pow(x + sqrt(y), 7);

cout << "|x + y| = " << result1 << endl;

cout << "|x| + |y| = " << result2 << endl;

cout << "x^3/y + y = " << result3 << endl;

cout << "sqrt(x^6 + y^5) = " << result4 << endl;

cout << "(x + sqrt(y))^7 = " << result5 << endl;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy