Unit 7
Unit 7
UNIT 7
OBJECTIVES
INPUT
7.0 Introduction
7.1.2 Grade
/* This program accepts the mark of 5 subjects, calculates and outputs the
average and its appropriate grade */
#include<iostream.h>
void main( )
{
float a,b,c,d,e,f ;
cout<<f<<endl;
if((f>=0) && (f<50))
{
cout<< “Grade is F”;
}
else if ((f>=50) && (f<62))
E3062/7/4
Writing C++ Program
{
cout<< “Grade is D-”;
}
else if ((f>=62) && (f<66))
{
cout<< “Grade is D”;
}
else if ((f>=66) && (f<69))
{
cout<< “Grade is D+”;
}
else if ((f>=69) && (f<72))
{
}
else if ((f>=86) && (f<89))
{
cout<< “Grade is B+”;
}
else if ((f>=89) && (f<92))
{
Activity 7A
Positive Negetive
/* This program evaluates the number keyed in is either a positive or negetive
value */
#include <iostream.h>
void main ( )
{
int n;
cout<< “Enter Value:”;
cin>>n
if((n>0) && (n!=0))
cout<<n<< “ n is a positive value”;
else
cout<<n<< “ n is a negetive value”;
}
E3062/7/7
Writing C++ Program
Feedback To Activity 7A
7.1.
INPUT
/* This program prompt 3 students details and list them accordingly( name,
id, and major) */
#include<iostream.h>
#include<string.h>
int i;
class student
{
private : string name;
int idno;
string major;
public : void insert( )
{
cout<< “\nEnter details of student:”<<endl;
cin>>name>>idno>>major;
}
void display ( )
{
cout<< “\n”<<name<< “ ” <<idno<< “ ”<<major<<endl;
}
}
void main ()
E3062/7/9
Writing C++ Program
{
student s[ 4 ];
for (i=1;i<4;i++)
s[ i ].insert();
cout<< “\n\nList of students”<<endl;
for( i=1;i<4; i++)
s[ i ] .display();
}
List of students
cout<<a[i] << “ ”;
cout<< “ \n”;
return 0;
}
OROGINAL ARRAY
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61 91 95
42 27 36 91 4 2 53 92
SORTED ARRAY
0 2 4 5 24 27 27 34 36 41 42 45 53 58 61 62 64
67 69 78 81 91 91 92 95
E3062/7/12
Writing C++ Program
Activity 7B
7.2. Write a program that checks whether the character you type is a vowel or not
with the following output
Feedback To Activity 7B
7.2.
/* This program checks whether the character typed is vowel or not */
#include<iostream.h>
using namespace std;
void main ()
{
char c;
cout<< “ Enter a character:”;
cin>>c;
switch (c)
{
case ‘a’:cout<< “It is a vowel character”;
break;
case ‘e’:cout<< “It is a vowel character”;
break;
case ‘i’:cout<< “It is a vowel character”;
break;
case ‘o’:cout<< “It is a vowel character”;
break;
case ‘u’:cout<< “It is a vowel character”;
break;
default:cout<< “It is a non – vowel character”;
}
}
E3062/7/14
Writing C++ Program
1.
SELF-ASSESSMENT
You are approaching success. Try all the questions in this self-assessment section
and check your answers with those given in the Feedback on Self-Assessment 2
given on the next page. If you face any problems, discuss it with your lecturer.
Good luck.
Question 7-1
Write a program that finds the square of the number entered with the following
format output:
Question 7-2
Write a program that accepts three values and selects the greatest number with the
following format output:
Feedback To Self-Assessment
Have you tried the question????? If “YES”, check your answer now:
Question 7.1
/* This program finds the square of the number entered*/
#include<iostream.h>
using namespace std;
void main( )
{
int a;
cout<< “Enter a value:”;
cin>>a;
cout<<endl<< “The square of ” <<a<< “ is”<<a*a;
}
Question 7.2
/* This program accepts three values and selects the greatest
number */
#include<iostream.h>
using namespace std;
void main ( )
{
int a,b,c;
E3062/7/16
Writing C++ Program
CONGRATULATIONS!!!!…..
May success be with you
always….