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

Document59 SIVA

The document contains 9 questions each with C++ code to solve different programming problems. Question 1 finds the largest of three numbers input by the user. Question 2 uses a switch statement to output a company name based on a code entered by the user. Question 3 calculates an electricity bill based on meter readings and consumption amount.

Uploaded by

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

Document59 SIVA

The document contains 9 questions each with C++ code to solve different programming problems. Question 1 finds the largest of three numbers input by the user. Question 2 uses a switch statement to output a company name based on a code entered by the user. Question 3 calculates an electricity bill based on meter readings and consumption amount.

Uploaded by

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

SIVAANESH KETHIRAVAN

19001353

Q1

#include <iostream>

using namespace std;

int main() {

float n1, n2, n3,largest;

cout << "Enter three numbers: ";

cin >> n1 >> n2 >> n3;

if(n1 >= n2)

largest=n1;

else

largest= n2;

if(n3 >largest)

largest= n3;

cout <<"the Largest numberis"<<largest<<endl;


return 0;

Q2

#include <iostream>

using namespace std;

int main()

int code;

cout << "Enter the code number: ";

cin >> code;

switch (code)

case 1: cout << "3M Corporation.";

break;

case 2: cout << "Maxell Corporation.";

break;

case 3: cout << "Sony Corporation.";


break;

case 4: cout << "Verbatim Corporation.";

break;

default: cout << "An invalid code number was entered.";

return 0;

Q3

#include <iostream>
using namespace std;
int main()
// (int argc, char** argv)
// The argc parameter represents the number of command line arguments.
// char *argv[] is an array of strings (character pointers) representing the individual arguments
provided on the command line.
// argc, or Argument Count, will be set to 4 (four arguments), and argv, or Argument Vectors, will be
populated with string pointers to "myprogram", "arg1", "arg2", and "arg3". The program invocation
(myprogram) is included in the arguments!

{
double units_consumed, bill;
float old_reading, new_reading;

//enter input items


cout << "Please enter new meter readings: ";
cin >> new_reading;
cout << endl;
cout <<"Please enter old meter readings: ";
cin >> old_reading;
cout << endl;

//calculate the units consumed


units_consumed = new_reading - old_reading;

//calculate the total bill

if (units_consumed<=1000)

bill = units_consumed*0.05;

if (units_consumed>1000&&units_consumed<=2000)

bill = units_consumed*0.07;

if (units_consumed>2000)

bill = units_consumed*0.10;

cout << "Units consumed: " << units_consumed << endl;

cout << "The amount that you owe is: " << "RM" << bill << endl;
return 0;
}

Q4
#include <iostream>
using namespace std;
int main ()
{

int m_year,weight;

cout << "Enter model year of the car: ";


cin>>m_year;

cout << "Enter weight of the car: ";


cin >> weight;

if (weight < 2700 && m_year <= 1970)


{
cout<<"Your weight class is 1."<<endl;
cout<<"Your registration fee is RM16.50."<<endl;
}

else if (weight >= 2700 && weight <= 3800 && m_year <= 1970)
{
cout<<"Your weight class is 2."<<endl;
cout<<"Your registration fee is RM25.50."<<endl;
}

else if (weight > 3800 && m_year <= 1970)


{
cout<<"Your weight calss is 3."<<endl;
cout<<"Your registration fee is RM46.50."<<endl;
}

else if (weight < 2700 && m_year > 1970 && m_year < 1980)
{
cout<<"Your weight class is 4."<<endl;
cout<<"Your registration fee is RM27.00."<<endl;
}

else if (weight >= 2700 && weight <= 3800 && m_year > 1970 && m_year < 1980)
{
cout<<"Your weight class is 5."<<endl;
cout<<"Your registration fee is RM30.50."<<endl;
}

else if (weight > 3800 && m_year > 1970 && m_year < 1980)
{
cout<<"Your weight class is 6."<<endl;
cout<<"Your registration fee is RM52.50."<<endl;
}

else if (weight < 3500 && m_year >= 1980)


{
cout<<"Your weight class is 7."<<endl;
cout<<"Your registration fee is RM19.50."<<endl;
}

else if (weight >= 3500 && m_year >= 1980)


{
cout<<"Your weight class is 8."<<endl;
cout<<"Your registration fee is RM52.50."<<endl;
}
return 0;
}

Q5

#include <iostream>

using namespace std;

int main()

int year ;

cout << "enter a year" ;

cin >> year ;


if (year % 4 == 0)

if (year % 100 == 0)

if (year % 400 == 0)

cout << year << "is a leap year." << endl;

else

cout << year << "is not a leap year." << endl;

else

cout << year << "is a leap year." << endl;

else

cout << year << "is not a leap year." << endl;

return 0;

SI

Q6

#include <iostream>
using namespace std;

int main()

int month ;

cout << "enter a month : ";

cin >> month ;

switch (month)

case 1 : cout << "31 days" ; break ;

case 2 : cout << "28 or 29 days" ; break ;

case 3 : cout << "31 days" ; break ;

case 4 : cout << "30 days" ; break ;

case 5 : cout << "31 days" ; break ;

case 6 : cout << "30 days" ; break ;

case 7 : cout << "31 days" ; break ;

case 8 : cout << "31 days" ; break ;

case 9 : cout << "30 days" ; break ;

case 10 : cout << "31 days" ; break ;

case 11 : cout << "30 days" ; break ;

case 12 : cout << "31 days" ; break ;

default : cout << "An invalid month was entered" ; break ;

return 0;

}
Q7

#include <iostream>
using namespace std;
// Function to check quadrant
void quadrant(int x, int y)
{
if (x > 0 and y > 0)
cout << "lies in first quadrant";

else if (x < 0 and y > 0)


cout << "lies in second quadrant";

else if (x < 0 and y < 0)


cout << "lies in third quadrant";

else if (x > 0 and y < 0)


cout << "lies in fourth quadrant";

else if (x == 0 and y > 0)


cout << "lies at positive y axis";

else if (x == 0 and y < 0)


cout << "lies at negative y axis";

else if (y == 0 and x < 0)


cout << "lies at negative x axis";
else if (y == 0 and x > 0)
cout << "lies at positive x axis";
else
cout << "lies at origin";
}
// Driver code
int main()
{
int x, y;
cout << "Enter x and y: ";
cin >> x >> y;
// Function call
cout << x << "," << y << " ";
quadrant(x, y);
return 0;
}

Q8

#include <iostream>

using namespace std;

int main()

char name[10];

float hour, wage, remain, socso;

cout << "Please enter employee's name: ";

cin >> name;


cout << endl;

cout << "Please enter the working hours: ";

cin >> hour;

cout << endl;

if (hour>60)

wage = wage + (40*5);

wage = wage + (20*8);

wage = wage + ((hour-60)*10);

else if (hour>40 && hour <=60)


{

wage = wage + (40*5);

wage = wage + ((hour-40)*8);

else if (hour<=40)

wage = wage + (hour*5);

socso = wage * 0.01;

cout << name << "'s pay slip." << endl;

cout << "Weekly wages: " << "RM" << wage << endl;

cout << "Contribution to Socso: " << "RM" << socso << endl;
return 0;

Q9

#include <iostream>

using namespace std;

int main() {

int x,y;

char ch;

cout << "Enter x: ";

cin >> x;

cout << endl;


cout << "Enter y: ";

cin >> y;

cout << endl;

cout << "Enter ch (a = add, m = multiply, s = subtract, d = divide or r = remainder): ";

cin >> ch;

switch (ch) {

case 'a': cout << x + y;

break;

case 'm': cout << x * y;

break;

case 's': cout << x - y;

break;

case 'd': cout << x / y;

break;
case 'r': cout << x % y;

break;

default: cout << "An invalid value was entered.";

return 0;

You might also like