Question

3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16...

3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16 marks]

     (b) Consider the following code fragments: If   a = 10; Evaluate the new value of “b” in the following:

               (i)   b =   ++ a;

              (ii) b = a ++;

            What value would a and b store in (i) and (ii) after program execution?

                                                                                                           [4 marks]

4. Create a C++ program that makes use of three arrays; name, mark, grade. The program should accept the names and marks of a number of students to be entered by the user. Use the number of students as the size of the arrays.
Grades are computed and stored in the grade array using the criteria:
100 – 60 = A;
59 – 40 = B;
below 40 = C.
The program should continuously request a user who enters a mark below 0 or above 100 to enter a mark in the range 0 – 100. Finally, the program should display the list of students in this format: Name | Mark   |   Grade
[20 marks]


Q5. Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and
seconds. This can be in 12:59:59 format, or each number can be entered at a separate prompt
(“Enter hours:”, and so forth).

The program should then store the time in a variable of type struct time, and finally print out the total number of seconds represented by this time value:
long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds [20 marks]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER :

Answer for (3) :-

(a)

Four features of Object-Oriented Programming OOP are :-

1. Abstraction

This refers to the fact that units in Object-Oriented Programming (also refers to classes) do not indicate the details or implementation. That is to say, the classes only specify the functionality to the outside world using objects without mentioning the implementation details or how the functions are actually working.

Example :- Employee class will have a method getEmployeeDetails without mentioning from where this data is fetched or how to fetch this.

2. Polymorphism

This refers to the concept that the same entity can exist in many forms in OOP.

Example :- a function getArea() will return the area of the figure based on the number and type of arguments passed to it, Like area of circle, rectangle etc

getArea(radius);

getArea(length, breadth);

Same name many forms.

Similarly operators can be overloaded in OOP languages like Cpp.

3. Inheritence

This refers to the concept that classes can exist in parent child heirarchy. A child class can inherit attributes or properties/ functionality from a parent class.

Example :- Employee class can inherit properties like name, gender from class person.

4. Encapsulation

This refers to the concept that all the objects in OOP are wrapped up or encapsulated that is all the attributes and functionality are present at one place called a class.

Example :- Student class will have student attributes like name, class, roll number and also the methods to fetch information like getStudentName(), getGrades() etc.

(b)

If a = 10;

then for the

(i)

#include <stdio.h>

int main()
{
int a,b;
a = 10;
b = ++a;
printf("ans is %d",b);

return 0;
}

Output will be 11

It is incrementing the value

(ii)

#include <stdio.h>

int main()
{
int a,b;
a = 10;
b = a++;
printf("ans is %d",b);

return 0;
}

Output will be 10.The value of variable b will remain same as variable a.

answer for (4) :-

Code :-

#include <iostream>
using namespace std;
main()
{
int n;
cout<<"Enter no.of students:";
cin>>n; //stores no.of students
int marks[n]; //declaring integer array for storing marks
string names[n],grade[n];//declaring string arrays to store marks and grade
for(int i=0;i<n;i++)
{
cout<<"Enter name of student:";
cin>>names[i];//stores name of every student
cout<<"Enter marks of student:";
cin>>marks[i]; //stores marks of every student
while(marks[i]>100 || marks[i]<0) //if user enters negative values or above 100 then again asks the user for input
{
cout<<"Enter a marks in the range 0 - 100:";
cin>>marks[i];
}
if(marks[i]>=60) //marks>60 and below 100 are given to be A grade
{
grade[i]="A";
}
else if(marks[i]>=40 && marks[i]<=59) //marks above 40 and below 60 are B grade
{
grade[i]="B";
}
else //marks below 40 are C grade
{
grade[i]="C";
}
}
cout<<"name\tmarks\tgrade\n"; //\t is used for tab space and \n is used for new line
cout<<"----------------------\n";
for(int i=0;i<n;i++)
{
cout<<names[i]<<"\t"<<marks[i]<<"\t"<<grade[i]<<"\n";
}
}

Code Screenshot :-

1 2 #include <iostream> using namespace std; main() int n; cout<<Enter no.of students:; cin>>n; //stores no. of students in

Output Screenshot :-

C:\Users\himanth\Documents\student.exe Enter no.of students:5 Enter name of student:himanth Enter marks of student: 88 Enter

answer for (5) :-

Code :-

#include <iostream>
using namespace std;
//structure defination is here
struct time
{
int hour;
int minute;
int seconds;
};

int main()
{ struct time d;
//taking values fro user
cout<<"Enter hours:\n";
cin>>d.hour;
cout<<"Enter minutes:\n";
cin>>d.minute;
cout<<"Enter Seconds:\n";
cin>>d.seconds;
//printing the results
cout<<"Total numbers of seconds is "<<d.hour*3600+d.minute*60+d.seconds;

return 0;
}

Code Screenshot :-

6 8 1 #include <iostream> 2 using namespace std; 3 //structure defination is here 4 struct time 5- { int hour; 7 int minute;

Output Screenshot :-

Enter hours: 1 Enter minutes: 35 Enter Seconds: 25 Total numbers of seconds is 5725 .Program finished with exit code 0 Press

Hope it helps... please give an upvote. It's very important to me... thank you:)

​​​​

Add a comment
Know the answer?
Add Answer to:
3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • c++ object oriented programming

    object oriented programming:Write a program that converts a number entered in decimal toRoman numerals. Your program should consist of a class, say, romanType. Anobject of type romanType should do the following:a. Store the number as a decimal.b. Convert and store the number into roman form.c. Print the number as a Roman numeral or decimal number as requestedby the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1

  • CSCI 161 - Lab 2: "Give Me a Second!" Overview This lab will have you developing...

    CSCI 161 - Lab 2: "Give Me a Second!" Overview This lab will have you developing a program that asks the user to input a time period as a number of seconds and in turn calculates the whole number of days, hours and minutes that are contained within the entered time period. Refer to the "Output Format" below for an example of what your program must do. The objectives of this lab are to reinforce and help teach: proper Java...

  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

  • In C++, write a complete program that receives a series of student records from the keyboard...

    In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • PROBLEM 2 MATLAB It is often important to validate if the user entered an acceptable input...

    PROBLEM 2 MATLAB It is often important to validate if the user entered an acceptable input to a program. For this problem, you may safely assume that the user only enters positive integer inputs (ie.do not consider the case where the user inadvertently enters letters casos hovond thase in the sample user has entered negative numbers). Emulate the output format below: your code should print the autput exactly as shown in the sample runs, Your code should also he generalized...

  • C++ A professor plans to store the following data for each of his students: Last Name,...

    C++ A professor plans to store the following data for each of his students: Last Name, First Name, Class Average (as a double), Letter Grade (“A”, “A-“, “B+”, “B”, etc.) Write two programs for writing and reading such a file, with the user choosing the file name. Store the (int) number of students as the first data value in the file, followed by \n. Then use the following delimiter scheme: Last Name(comma)First Name(comma)Average(space)Letter Grade(newline) For the file writer program, input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT