0% found this document useful (0 votes)
34 views

EC-102

Uploaded by

rsaed8874
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)
34 views

EC-102

Uploaded by

rsaed8874
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/ 18

1 program

#include <iostream>
using namespace std;

int main()
{
int num1;
int num2;
int sum;

cout<<"Enter the first number: ";


cin>>num1;

cout<<"Enter the secound number: ";


cin>>num2;

sum=num1+num2;
cout<<"the sum is:"<<sum<<endl;

return 0;
}

2 program

#include <iostream>

using namespace std;

int main()
{
int num1;
int num2;

cout<<"Enter two numbers to compare"<<endl;


cin>>num1>>num2;

if(num1>num2){
cout<<num1<<">"<<num2<<endl;
}

if(num1<num2){
cout<<num1<<"<"<<num2<<endl;
}

if(num1==num2){
cout<<num1<<"="<<num2<<endl;
}
if(num1!=num2){
cout<<num1<<"!="<<num2<<endl;
}
if(num1>=num2){
cout<<num1<<">="<<num2<<endl;
}
if(num1<=num2){
cout<<num1<<"<="<<num2<<endl;
}
return 0;
}

OR

#include <iostream>

using namespace std;

int main()
{
int num1;
int num2;

cout<<"Enter two numbers to compare"<<endl;


cin>>num1>>num2;

num1>num2 ? cout<<num1<<">"<<num2<<endl : cout<<num1<<"<="<<num2<<endl;

num1==num2 ? cout<<num1<<"="<<num2<<endl : cout<<num1<<"!="<<num2<<endl;

num1>=num2 ? cout<<num1<<">="<<num2<<endl : cout<<num1<<"<"<<num2<<endl;

return 0;
3 program

#include <iostream>
using namespace std;

class gradebook
{
public:

void displaymessage()
{
cout<< "welcome to the grade book";
}
};

int main()
{
gradebook mygradebook;
mygradebook.displaymessage();

4 program
#include <iostream>
#include <string>
using namespace std;

class gradebook
{
public:
void displaymessage(string namecourse)
{
cout<< "welcome to the grade book for\n"<<namecourse<<"!"<<endl;
}
};

int main()
{
string coursename;
gradebook mygradebook;

cout<<"Please enter the course name:"<<endl;


getline(cin,coursename);
cout<<endl;

mygradebook.displaymessage(coursename);

}
5 program
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
for(unsigned int counter = 1 ; counter<=20; counter++)
{
cout<<setw(10)<<(1+ rand() % 6);
if (counter % 5==0)
cout<<endl;
}

return 0;
}

6 program
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
srand(time(NULL));

int num=6;
int result=0;

result = rand() %6 + 1;

switch(result)
{
case 1:
cout<<"You are winned"<<endl;
break;

case 6:
cout<<"You are losted"<<endl;
break;
default:
cout<<"what are you doing"<<endl;
break;
}
cout<<"Result: "<<result<<endl;
return 0;
}

7 program
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{

unsigned int f1= 0;


unsigned int f2= 0;
unsigned int f3= 0;
unsigned int f4= 0;
unsigned int f5= 0;
unsigned int f6= 0;

for (unsigned int roll=1; roll<=6000000; ++roll )


{
unsigned int face = 1+ rand()%6;

switch(face){
case 1:
++f1;
break;

case 2:
++f2;
break;

case 3:
++f3;
break;

case 4:
++f4;
break;

case 5:
++f5;
break;

case 6:
++f6;
break;

default:
cout<<"program should never get her!";
break;
}
}

cout<<"face"<<setw(13)<<"frequency1"<<endl;
cout<<"\n 1"<<setw(13)<<f1;
cout<<"\n 2"<<setw(13)<<f2;
cout<<"\n 3"<<setw(13)<<f3;
cout<<"\n 4"<<setw(13)<<f4;
cout<<"\n 5"<<setw(13)<<f5;
cout<<"\n 6"<<setw(13)<<f6;

return 0;
}
8 program
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
unsigned int seed=0;
cout<<"Enter seed";
cin>>seed;
srand(seed);

for(unsigned int counter = 1; counter<=10; ++counter)


{
cout<<setw(13)<<(1+rand()%6);

if(counter %5==0)
cout<<endl;

return 0;
}
9 program
#include <iostream>

using namespace std;

int square( int );

int main()
{
int a =10;
cout<< a <<" squared "<<square(a)<<endl;

}
int square(int x)
{
return x*x;
}

10 program
#include <iostream>

using namespace std;

class gradeBook
{
private:
int total;
int counterGrade;
int grade;

public:

gradeBook()
{
cout<<"Welcome to the grade book for\n CE102 C++ programing"<<endl;
}
int TotalGrade()
{

int total=0;
int counterGrade=1;
while(counterGrade <=10)
{
cout<<"Enter a grade: ";
cin>>grade;

total=total+grade;
counterGrade++;
}
int ave = total/10;
cout<<"The total of all 10 grades is:"<<total<<endl;
cout<<"class average is: "<<ave;
}

};

int main()
{
gradeBook g1;
g1.TotalGrade();

return 0;
}
11 program
#include <iostream>
#include <iomanip>
using namespace std;

class gradeBook
{
private:
int total;
int counterGrade;
int grade;

public:

gradeBook()
{
cout<<"Welcome to the grade book for\n CE102 C++ programing"<<endl;
}
int TotalGrade()
{

int total=0;
int counterGrade=0;
int grade =0;
while(grade != -1)
{
cout<<"Enter -1 if you want to stop."<<endl;
cout<<"Enter a grade: ";
cin>>grade;
total=total+grade;

counterGrade++;
}
if (counterGrade!=0)
{
double ave = static_cast<double>(total)/counterGrade;
cout<<"total of all "<<counterGrade<<" grades is:"<<total<<endl;
cout<<setprecision( 2 )<<fixed;
cout<<"class average is: "<<ave;
}

};

int main()
{
gradeBook g1;
g1.TotalGrade();

return 0;
}

12 program
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double a=0;
double p=1000.0;
double r;
double x=0;

for(int i =1; i<=10; i++)


{
cout<<"Enter an interset rate for year: "<<i<<endl;
cin>>r;
if(i==1)

a = p*pow(1+r,1);
x=a;
a=a*pow(1+r,1);
}
cout<<"the result is "<<x<<endl;

return 0;
}

13 program
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class Grade
{
private:
int grade;

public:
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
Grade ()
{

cout << "Enter the letter grades: " << endl;


cout << "Enter the EOF character to end input." << endl;

while ((grade = cin.get ()) != EOF)


{
switch (grade)
{
case 'A':
case 'a':
++a;
break;

case 'B':
case 'b':
++b;
break;

case 'C':
case 'c':
++c;
break;

case 'D':
case 'd':
++d;
break;

case 'F':
case 'f':
++f;
break;

case '\n':
case '\t':
case ' ':
break;

default:
cout<<"Incorrect letter grade entered"<<endl;
cout<<"Enter a new grade:"<<endl;
break;
}
}
}
void display(){

cout<<"Number of students who received letter grade:"<<endl;


cout<<"A: "<<a<<endl;
cout<<"B: "<<b<<endl;
cout<<"C: "<<c<<endl;
cout<<"D: "<<d<<endl;
cout<<"F: "<<f<<endl;

};

int
main ()
{
Grade g;
g.display();

return 0;
}
14 program
#include <iostream>

using namespace std;


int boxValue(int l=1, int w=1, int h=1);

int main ()
{
cout<<"the default value is: "<<boxValue()<<endl;
cout<<"the value of a box with length 10\n"
<<"wight 1 and heigh 1 is: "<<boxValue(10)<<endl;
cout<<"the value of a box with length 10 \n "
<<"wight 5 and heigh 1 is: "<<boxValue(10,5)<<endl;
cout<<"the value of a box with length10\n"
<<"wigth 5 and heigh 2 is: "<<boxValue(10,5,2)<<endl;

int boxValue(int l, int w, int h)


{
return l*w*h;
}
15 program
#include <iostream>

using namespace std;


int square (int x)
{
cout<<"Square of integer "<<x<<" is: ";
return x*x;
}

double square (double y)


{
cout<<"square of double "<<y<<" is: ";
return y*y;
}

int main ()
{
cout<<square(7)<<endl;
cout<<square(7.5);

}
First class program

#include <iostream>
using namespace std;

class retctangel
{
private:
int w;
int l;

public:

int raid(int x, int y)


{

w=x;
l=y;
}

int a()
{
return (w * l);
}

int c()
{
return ((w + l)*2);
}

};

int main()
{
retctangel r1;
r1.raid(5,7);

// r1.w=5;
// r1.l=8;

//cin>>r1.w;
//cin>>r1.l;

cout<<r1.a()<<endl;
cout<<r1.c();

return 0;
}
Second class program

#include <iostream>

using namespace std;

class culc
{
private:
int n1 , n2;

public:

culc()
{

cout<<"Enter the first number:"<<endl;


cin>>n1;
cout<<"Enter the secound number:"<<endl;
cin>>n2;
}

int sum(){
return n1+n2;
}

int sub(){
return n1-n2;
}

int mult(){
return n1*n2;
}

int divi(){
return (float) n1 / (float) n2;
}

int mod(){
return n1 % n2;
}

};

int main()
{
culc c;

cout<<"there sum is:"<<c.sum()<<endl;


cout<<"there sub is:"<<c.sub()<<endl;
cout<<"there mult is:"<<c.mult()<<endl;
cout<<"there divi is:"<<c.divi()<<endl;
cout<<"the mod is:"<<c.mod()<<endl;

return 0;
}
3rd class program
#include <iostream>

using namespace std;

class product
{

private:
string name;
int year;
int price;

public:

product()
{

cout<<"Enter product information:"<<endl;


cin>>name>>year>>price;

}
void print()
{
cout<<"product's name is: "<<name<<endl;
cout<<"product's year is: "<<year<<endl;
cout<<"product's price is: "<<price<<endl;

}
string getName()
{
return name;
}
int getPrice()
{
return price;
}
int getYear()
{
return year;
}
void setPrice(int p)
{
price = p;
}
void setYear(int y)
{
year = y;
}

};

int main()
{
product p1;
//product p2;
cout<<endl;

p1.print();
cout<<endl;
/*p2.print();
cout<<endl;*/

p1.setPrice(2020000);
p1.setYear(2020);

p1.print();
cout<<endl;

/*if (p1.getYear() < p2.getYear())


cout<<p1.getYear()<<" is oldder "<<endl;
else
cout<<p2.getYear()<<" is oldder "<<endl;

if(p1.getPrice() > p2.getPrice())


cout<<p1.getName()<<" is more expensive."<<endl;
else
cout<<p2.getName()<<" is more expensive."<<endl;*/

//p1.getName();

//cout<<p1.getName()<<endl;

return 0;
}

4th class program


#include <iostream>

using namespace std;

class GradeBook
{
private:
int x, y, z;
public:
GradeBook(){
cout<<"Enter three grades:"<<endl;
cin>>x>>y>>z;

}
void disPlay(){
cout<<"Welcome to the grade book for\nCS101 C++programming!"<<endl;
}
int maximum(){

int maximumValue = x;

if(y > maximumValue)


maximumValue = y;
if(z > maximumValue)
maximumValue = z;
cout<<"Maximum Grade entered: "<<maximumValue;

return maximumValue;

};

int main()
{
GradeBook g1;
g1.disPlay();
g1.maximum();

return 0;
}

You might also like