Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C/C++ Final Project 1. Create a program that interacts with the user. 2. Use at

ID: 3691751 • Letter: C

Question

C/C++ Final Project 1. Create a program that interacts with the user. 2. Use at least 3 objects (instances of different classes) 3. Use at least one example of inheritance 4. Use at least one example of polymorphism (EXTRA CREDIT) 5. Use at least one pointer 6. Use at least one pass by reference 7. Use at least one overloaded function 8. Use separate files for class definition, class function definition, cpp file that has main 9. Use at least 2 loops 10. Use at least 2 selection statements 11. Include at least one array 12. Include a write to a file 13. Include a read from file 14. Include data validation.

Explanation / Answer

#include <iostream>
#include <iomanip>
using std::setw;
using namespace std;

void interactsUser ();
void simplePointer();
void ifElse();
void switchCase();
void ArrayElements();
void readWritefiles();
void passByReference(int *x, int *y)
{
int *temp;
*temp = *x;
* x = *y;
*y = *temp;

}


int main() {
int a = 100;
int b = 200;

interactsUser();
simplePointer();
passByReference(&a,&b);
ifElse();
switchCase();
readWritefiles();

Shape *shape;
Rectangle rec(10,7);
Triangle tri(10,5);
shape = &rec;
shape->area();
shape = &tri;
shape->area();

return 0;
}

void simplePointer(){
int var1;
char var2[10];
cout << "Address of var1 variable: ";
cout << &var1 << endl;
cout << "Address of var2 variable: ";
cout << &var2 << endl;
}
void interactsUser(){
float n1, n2, sum;
cout << "Enter two numbers: ";
cin >> n1 >> n2;
sum = n1+n2;
cout << "Sum = " << sum;
  
}
void ifElse()
{
int a = 100;
if( a < 20 )
{
cout << "a is less than 20;" << endl;
}
else
{
cout << "a is not less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
}
void ArrayElements()
{
int n[ 10 ];
for ( int i = 0; i < 10; i++ )
{
n[ i ] = i + 100;
}
cout << "Element" << setw(13) << "Value" << endl;
  
for ( int j = 0; j < 10; j++ )
{
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}

}

void switchCase()
{
int a = 10;

char grade = 'D';

switch(grade)
{
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
case 'C' :
cout << "Well done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case 'F' :
cout << "Better try again" << endl;
break;
default :
cout << "Invalid grade" << endl;
}
cout << "Your grade is " << grade << endl;
}
void readWritefiles() {
char data[100];
ofstream outfile;
outfile.open("file.txt");
cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);
outfile << data << endl;
cout << "Enter your age: ";
cin >> data;
cin.ignore();
outfile << data << endl;
outfile.close();
ifstream infile;
infile.open("file.txt");
cout << "Reading from the file" << endl;
infile >> data;
cout << data << endl;
infile >> data;
cout << data << endl;
infile.close();
}
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
cout << "Parent class area :" <<endl;
return 0;
}
};
class Rectangle: public Shape{
public:
Rectangle( int a=0, int b=0):
Shape(a, b) { }
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};
class Triangle: public Shape{
public:
Triangle( int a=0, int b=0):Shape(a, b) { }
int area ()
{
cout << "Triangle class area :" <<endl;
return (width * height / 2);
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote