We have been working very hard since 2009 to facilitate in learning Read More. We can't keep up without your support. Donate.


Assignment No. 01
Semester: Fall 2014
CS304: Object Oriented Programming Total Marks: 20

Due Date:20/11/2014

Instructions:

Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:

§1 The assignment is submitted after due date.
§2 The submitted assignment does not open or file is corrupt.
§3 Assignment is copied(partial or full) from any source (websites, forums, students, etc)

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files or .exe file, no reward will be given in any case.


Objective:

The objective of this assignment is to provide hands on experience of:

§1 Basic concepts of classes and objects in C/C++ language
§2 Dealing with member functions
§3 Dealing with Constructors
§4 Calling member functions through objects of classes
§5 Saving a program
§6 Compiling a program
§7 Executing the program

Guidelines:

§ Code should be properly indented and well commented.
§1 Follow C/C++ guide lines while writing variable names, function names etc
§2 Use only dev-C++ for this assignment.


Assignment
Problem Statement:
Write the C++ language program that should fulfill the following requirements:
Program should contain two classes as “Student” and “Instructor”. Within main() function, create the objects of these two classes. Display your student ID and name by passing as attributes(student ID, name) while instantiating the object of the “Student” class. Using the object of the Instructor Class, call its member function Input() to take input for the height of the 8 instructors then call its member function print() to display the average height of the instructors.
Declare data members by private and member functions by public access specifier for both classes.

Function
Description

main() function
Objects of both classes will be created in it, and respective member functions of these objects will be called.

Student(char *, char *)
Constructor of the Student class to display your own student ID and name

input()
Function of Instructor class , it will take heights as input of 8 instructors

print()
Function of Instructor class, it will display average height of 8 instructors.


Detailed Description:

Your program should display your own student ID and name on the top of the screen through passing as attributes at the time of instantiating object of the Student class i.e.
Student ID : MC104403787
Student Name : Rehman

Member function input() of the “Instructor” class should take height as input of the 8 instructors from the user i.e.

Enter Instructor 1 Height in Feet : 5.5

Member function print() of the “Instructor” class should display average height of the Instructors.
Sample output of the program:


BEST OF LUCK!

For any query about the assignment, contact at cs304@vu.edu.pk

Views: 6970

Replies to This Discussion

Why this Solution giving an error..

#include <iostream>
#include <cstdlib>
#include <string.h>
#include <stdlib.h>

using namespace std;
//starting the student class
class Student {

private:
char * StudentID;
char * StudentName;

public:
Student(char *, char *);
void print(); //parametarized constructor of student class 
~Student(); //destructor of student class

};

Student::Student(char *id, char *name) {
StudentID = id;
StudentName = name;
}

void Student::print() {
cout "Student ID :" StudentID endl;
cout "Student Name :" StudentName "\n\n";
}

Student::~Student() {

}

class Instructor{
private:
float age[8];

public:
Instructor(){ }
~Instructor(){ }
void input();
void print();
};

void Instructor::input() {

int i;

for(i=1; i<=8; i++) {
cout "Enter Instructor 1 Height in feet: 4.9\n";
cout"\n";
cout "Enter Instructor 2 Height in feet: 5.8\n";
cout"\n";
cout "Enter Instructor 3 Height in feet: 5.9\n";
cout"\n";
cout "Enter Instructor 4 Height in feet: 5.7\n";
cout"\n";
cout "Enter Instructor 5 Height in feet: 6\n";
cout"\n";
cout "Enter Instructor 6 Height in feet: 5.8\n";
cout"\n";
cout "Enter Instructor 7 Height in feet: 5.4\n";
cout"\n";
cout "Enter Instructor 8 Height in feet: 5.9\n";
cout"\n";
cout"Average Height in Feet:5.675\n";
cin >> age[i];
cout "\n\n"; 
}
}

void Instructor::print()
{
int i;
for(i=1; i<=8; i++)
{
cout "\nAverage Height in Feet : 5.675";
cout"\n";
}
}
int main() {

Student student1((char *)"BC1400000", (char *)"Khan");
student1.print();

Instructor heights;
heights.input();
heights.print();
cout "\n\n";

system("pause");
}

 

Because double less than sign is missing after every cout 

kisi ka lms on ho raha hy?

koi to full solution share kry plzzzzzzzzzzzzzzzzzzzzzzzzz :( :( :(

/*****************************
Jamil Akhtar BCxxxxxxxxxxxx
Course CS304
Assignment No.1 
Semester Fall 2014
Date: 21/11/2014
*****************************/
/* Header files */
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

/* Creating Student class with studentname and studentid attributes
and mark them as private so can only be accessible by the class itself
and member methods of the class. Declaring parametrized constructor which 
takes two string arguments name and id and used to initilize studentname 
and studentid variables. A display method is used to print student info.
*/
class Student
{
private:
std::string studentName;
std::string studentID;

public:
Student(string name, string id)
{
studentName = name;
studentID = id;

void display()
{
std::cout"Student ID : " studentIDendl;
std::cout"Student Name : " studentNameendl;

}

/* Deconstructor */ 
~Student()
{
}

};

/*
Declaring an instructor class with private averageHeight and counter variable.
An int public variable i which is used to loop through elements of height array
of 8 different heights of instructors. Input methods for getting the user inputs
and calculating the total and average heights of instructors. Finally print method
print total and average height of 8 instructors to command prompt.
*/

class Instructor
{
private:

double averageHeight;
int counter;

public:
int i;


Instructor()
{

}


void input()
{
double height[8];
double totalHeight = 0;
counter = 0;
for( i = 1; i <= 8; i++)
{
cout"please enter height of Instructor " i " : ";
cin>> height[i];
totalHeight += height[i];
counter++;

}
cout"Total height : " totalHeight endl;
averageHeight = totalHeight/counter;

}

void print()
{

cout"Average Height in feet is : "averageHeight" Feet"endl;

}

/* deconstructor */

~Instructor()
{
}
};



/* Main starting point of the program */

int main()
{
/*
Creating two objects pupil and teacher from Student and Instructor
class respectively. Calling memeber function display() of student 
class to print student info. Then calling Instructor class input() 
method to get user input store 8 different instructors heights in 
height[] array and calculate total and average heights. Lastly 
print() method of Instructor class being called to display the 
total and average heights of 8 instructors.
*/

Student pupil("xxxxxxxxxxx", "BCxxxxxxxxxx");
Instructor teacher;
pupil.display();
teacher.input();
teacher.print();
system("pause");
return 0;

/* end of main method */
}

complete solution please fast koi to kr dy 

Assignment no. 1 due date has been extended till 24th November 2014. Upload your assignment on VU-LMS accordingly.

Assignment done with out any error.

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service