C++ Programming Club-Lecture 2

  • 582 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
582
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
14
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. C++ Programming Club Lecture 2
  • 2. • If Else Statement• The if-else structure directs the computer to select between two statements based on the result of a comparison.For example:If (n<0) cout”The number is negative”;ElseCout<<“The number is positive”;
  • 3. • Logical Operators
  • 4. • Use Of Else if:• If there are more than 2 conditions then we can use else if with the condition inside ().• For Example: if (grade>80 && grade<100)Cout<<“Excellent”;Else if ( grade>70 && grade<80)Cout<<“Good”Elsecout<<“Average”
  • 5. • Another ProblemWrite a Program by using if-else statement forthe following data:Specification Status CodeSpace exploration SMilitary grade MCommercial grade CToy grade T
  • 6. • Solution:#include <iostream>using namespace std;void main(){char code; // the variable is named code and it is in the form of a character or alphabetcout << "Enter a specification code: "; //output on the screencin >> code; //inputif (code == S) // if we enter S the following will be the o/p and likewise forothercout << "The item is space exploration grade."; //alphabet(code)else if (code == M)cout << "The item is military grade.";else if (code == C)cout << "The item is commercial grade.";else if (code == T)cout << "The item is toy grade.";elsecout << "An invalid code was entered."; // if we type an alphabet other than S,M,C,T this will bethe o/pcout << endl; // on the screensystem ("pause");}
  • 7. • Homework1-If an angle is equal to 90 degrees, print the message “The angle is aright angle”;else, print the message “The angle is not a right angle.”2-(Data Processing) A student’s letter grade is calculated according tothe following schedule:Numerical Grade Letter GradeGreater than or equal to 90 ALess than 90 but greater than or equal to 80 BLess than 80 but greater than or equal to 70 CLess than 70 but greater than or equal to 60 DLess than 60 FUsing this information, write a C++ program that accepts a student’snumerical grade,converts the numerical grade to an equivalent lettergrade, and displays the letter grade.
  • 8. Lets Practice This Problem….• A certain waveform is 0 volts for time less than 2 seconds and 3 volts for time equal to or greater than 2 seconds. Write a C++ program that accepts time in the variable named time and displays the appropriate voltage, depending on the input value.
  • 9. • Solution#include<iostream>using namespace std;void main (){ int time; //variable is called time and is in the form of integer cout<<"Enter time :"; //display on the screen cin>>time; //input if (time<2) //selection statement cout<<"0 volts"; else if (time>=2) cout<<"3 volts"; cout<<endl; //output system ("pause");}