0

Hey, I get confused when dealing with the static scope and dynamic scope, and for this pseudocode I have to find both. For static I believe it should print out: 9 4 2 3 however, I'm not entirely sure. Any help would be appreciated, thanks.

[CODE]Procedure main
g:integer

procedure B(a : integer)
    x:integer

procedure A(n:integer)
    g:=n

procedure R(m:integer)
    write_integer(x)
    x/:=2—integer division
    if x>1
        R(m + 1)
    else
        A(m)
--body of B
x:=a X a
R(1)

--body of main
B(3)
write_integer(g)
[/CODE]

0

Hi, I'm having trouble finding out whether I am doing my diagram the correct way or not. These are some of the properties of the diagram.

Make an ER diagram and tables of the diagram:
-Classroom contains the name of the building, the building number, and the space.
-Reservation contains the day, hours and the expected amount of space.
-Only the professor can reserve a room
-Each course contains name / id And professor.
-Each course must have a classroom
-Only one professor per course

I believe the Classroom and Course are the two entities and Reservation is the relation, also professor would be an attribute for course. For now I am not going to focus on the constraints and whatnot as I am in a hurry, but another way that has put doubts in my mind, is that the diagram is a ternary. Classroom, course, and professor are all entities connected to the relation Reservation, but that is what confuses me. Any tips or help would be appreciated, and if you need any more info let me know. In the meantime, I'm going to keep trying to figure it out. Thanks.

0

Hey there, I can't seem to figure out why i can't access the member '*next' from the Node class to the Shuffle function. Any help would be great.

[CODE]/* llist.h

  • LList
    */

include <iostream>

include <string>

using namespace std;

typedef string ElementType;

class LList;
class Node {
protected:
ElementType data;
Node *next;

public:
Node() {next=NULL;};
Node(ElementType d) {data=d; next=NULL;}
Node* GetNext() {return next;};
ElementType GetData() {return data;};
friend class LList;
friend ostream& operator<< (ostream &, Node &);
friend ostream& operator<< (ostream &out, LList &li);

};

class LList {
protected:
Node *first;
int mySize;

public:
LList() {first = NULL; mySize = 0;}
~LList();
void Insert(ElementType, Node );
Node
InsertAndReturn(ElementType, Node );
void InsertFirst(ElementType);
void Delete(Node
);
void DeleteFirst();
void DeleteAll();
int FindFirst(ElementType);
friend ostream& operator<< (ostream &out, LList &li);
LList& operator= (const LList &li);
friend LList* Shuffle(LList & , LList &);
friend class Node;
};[/CODE]

[CODE]/* llist.cpp

  • Implementation of member functions for the classes Node and LList.
    */

include "llist.h"

using namespace std;

ostream& operator<< (ostream &out, Node &n)
{
out << n.data;
return out;
}

//
// Destructor for the List class. Must remember to delete the linked list.
//

LList::~LList() {
while (first != NULL) {
DeleteFirst();
}
}

//
// Preconditions: The list has been created
// Postconditions: A node will be added after the one pointed by p.

void LList::Insert(ElementType e, Node p) {
Node
n = new Node(e);

if (p == first) {
    n->next = first;
    first = n;
}
else {
    n->next = ...
0

Hey there, I'm having trouble creating a multiplication function for the program as I have two classes to keep in mind (Monomial and Polynomial). And if possible, a little advice on how to make my for statements in the arithmetic operators more flexible to user input such as i<PolynomialSize, which I just can't seem to find a way around it. So any help or hints would be helpful. My functions work partially, by the way. Here's what I got so far:

[CODE]/-- Polynomial.h ---------------------------------------------------------
Defines the monomial and polynomial classes. Polynomial is implemented
basically as a list of monomials.
---------------------------------------------------------------------------
/

include <iostream>

ifndef PNOM

define PNOM

const int CAPACITY = 1024;
//typedef int ElementType;

class Monomial {
private:
float coef;
int exp;
public:
Monomial(){};
/*----------------------------------------------------------------------
Construct a Monomial object.

 Precondition:  None
 Postcondition: An empty Monomial object has been constructed..

-----------------------------------------------------------------------/
Monomial(float c,int p) { coef = c; exp = p;};
/
----------------------------------------------------------------------
Construct a Monomial object with specified coeffient and exponent.

 Precondition:  None
 Postcondition: A Monomial object has been constructed with the 
              specified coeffient and exponent.

-----------------------------------------------------------------------/
friend Monomial operator+ (Monomial&, Monomial&);
/
----------------------------------------------------------------------
Overloading the operator+ so we can sum two monomials.

 Precondition:  The monomials have the same exponent.
 Postcondition: A Monomial object has been created and returned.

-----------------------------------------------------------------------*/

/-----------------------------------------------------------------------------------------------/
//Prototypes for the functions of the exercise #5 of the homework.

friend Monomial operator- (Monomial&, Monomial&);
/*----------------------------------------------------------------------
 Overloading the operator- so we can substract two monomials.

 Precondition:  The monomials have the same exponent.
 Postcondition: A Monomial object has been created and ...
0

Hey there, I'm having trouble figuring out the next step of my program. What I'm trying to do is make a function that will add two polynomials, and I don't know how to exactly fix it. My first question would be if the Polynomial operator+ function is right, or whether it needs some fixing. Any hints or advice would be appreciated. Here's my code:

[CODE]/-- Polynomial.h ---------------------------------------------------------
Defines the monomial and polynomial classes. Polynomial is implemented
basically as a list of monomials.
---------------------------------------------------------------------------
/

include <iostream>

ifndef PNOM

define PNOM

const int CAPACITY = 1024;
//typedef int ElementType;

class Monomial {
private:
float coef;
int exp;
public:
Monomial(){};
/*----------------------------------------------------------------------
Construct a Monomial object.

 Precondition:  None
 Postcondition: An empty Monomial object has been constructed..

-----------------------------------------------------------------------/
Monomial(float c,int p) { coef = c; exp = p;};
/
----------------------------------------------------------------------
Construct a Monomial object with specified coeffient and exponent.

 Precondition:  None
 Postcondition: A Monomial object has been constructed with the 
              specified coeffient and exponent.

-----------------------------------------------------------------------/
friend Monomial operator+ (Monomial &, Monomial &);
/
----------------------------------------------------------------------
Overloading the operator+ so we can sum two monomials.

 Precondition:  The monomials have the same exponent.
 Postcondition: A Monomial object has been created and returned.

-----------------------------------------------------------------------/
friend ostream & operator<< (ostream & out, const Monomial & mono);
/
----------------------------------------------------------------------
Overloading the OUTPUT operator for Monomials.

 Precondition:  None.
 Postcondition: The coefficient and exponent (if != 0) of the monomial are 
                displayed in the default output device.

-----------------------------------------------------------------------*/
};

typedef Monomial ElementType;

class Polynomial
{
public:

Polynomial();
/*----------------------------------------------------------------------
Construct a List object.

 Precondition:  None
 Postcondition: An ...
0

[CODE]// LoadMemory function
void Simpletron::LoadMemory(){
// Precondition: This function receives the following variables.
ifstream MySimpletron; // To read the file named MySimpletron.
string file; // To store the name of the file.

//Postcondition: This function loads the instructions from the file into the program.
cout << "\nEnter the name of the file: " << endl; // This indicates that it is ready for input.
cin >> file; // To input the name of the file.

    MySimpletron.open(file.c_str(),ifstream::in); // To open the file. 

    if(MySimpletron.fail()){ // This indicates that the file was not able to open.
        cout << "\nThe file was not able to be opened because it does not exist. " << endl;
        exit(1);
    }   

    cout << "\nThe instructions contained in the file " << file << " are the following: " << endl;

    size = 0; // To clean the array when it opens the file again.

        while (MySimpletron >> instructionRegister){ // It keeps reading the file until it ends.
            memory[size] = instructionRegister;
            cout << setfill('0') << setw(4) << memory[size] << "    ";
            size++;
        }

    cout << "\nThe information in the file has been read." << endl; 

    cout << "\n*** Program loading completed ***" << endl;
    cout << "*** Program execution begins  ***" << endl;

    MySimpletron.close(); // To close the file.

system ("pause");

}[/CODE]

0

Hey there, I'm having trouble getting my program to read the last instruction of the file, and so far, I haven't been able to figure out why. Any help would be appreciated.

[CODE]/ The Simpletron Machine Language Program.
The purpose of this program is to simulate a primitive computer.
This program written in C++, a high-level language, will read and
execute the program instructions written in machine language from
an input file. Then, the program should display the registers and
the simulated computer memory.
/

/ The functions used in the program are:
Simpletron();
void Instructions();
void DisplayMemory();
void LoadMemory();
void Execute();
/

include <iostream>

include <iomanip>

include <fstream>

include <string>

include <cstdlib>

using namespace std;

// Input/Output operations
const int READ = 10; // Reads a variable and places it into a specific memory location.
const int WRITE = 11; // Writes a variable from a specific memory location into the terminal.

// Load/Store operations
const int LOAD = 20; // Loads a variable from a specific memory location into the accumulator.
const int STORE = 21; // Stores a variable from the accumulator into a specific memory location.

// Arithmetic operations
const int ADD = 30; // Adds a variable from a specific memory location to a variable in the accumulator.
const int SUBTRACT = 31; // Substracts a variable from a specific memory location from a variable in the accumulator.
const int DIVIDE = 32; // Divides a variable from a specific memory location into a variable ...

1

Hey, well my partner and I changed it up a bit, but now the program does not exit due to HALT, instead it is because of ERROR. Also, the last instruction won't display, and could you give a couple of examples of redundancy errors/data duplication? Anyhow, here's the update and thanks for your help:

[CODE]#include <iostream>

include <iomanip>

include <fstream>

include <string>

include <cstdlib>

using namespace std;

const int READ = 10;
const int WRITE = 11;

const int LOAD = 20;
const int STORE = 21;

const int ADD = 30;
const int SUBTRACT = 31;
const int DIVIDE = 32;
const int MULTIPLY = 33;

const int BRANCH = 40;
const int BRANCHNEG = 41;
const int BRANCHZERO = 42;

const int HALT = 43;

bool ERROR;
//# define Msize 100;

class Simpletron{
private:
int accumulator;
int instructionCounter;
int operationCode;
int operand;
int instructionRegister;
int memory[];

public:
    Simpletron(){};
    void LoadMemory();
    void DisplayMemory();
    void Execute();

};

void Instructions(void);

int main(){
Simpletron mycomputer;

Instructions();

mycomputer.LoadMemory();    
mycomputer.Execute();

return 0;

}

// Functions

void Instructions(){
cout << " Welcome to Simpletron! " << endl;
cout << " Please enter your program one instruction " << endl;
cout << " (or data word) at a time. I will type the " << endl;
cout << " location number and a question mark (?). " << endl;
cout << " You then type the word for that location. " << endl;
cout << " Type the sentinel -99999 to stop entering " << endl; ...

1

Hey there, I'm having trouble getting my program to read every instruction to then execute it, as well as displaying everything correctly. Right now my program displays mainly garbage and for now I simply want it to be able to successfully run a simple addition program, so any advice or hints, or even any links to send me for info would be great.
Here's my program so far:

[CODE]#include <iostream>

include <iomanip>

include <fstream>

include <string>

include <cstdlib>

using namespace std;

const int READ = 10;
const int WRITE = 11;

const int LOAD = 20;
const int STORE = 21;

const int ADD = 30;
const int SUBTRACT = 31;
const int DIVIDE = 32;
const int MULTIPLY = 33;

const int BRANCH = 40;
const int BRANCHNEG = 41;
const int BRANCHZERO = 42;

const int HALT = 43;

bool ERROR;
//# define Msize 100;

class Simpletron{
private:
int accumulator;
int instructionCounter;
int operationCode;
int operand;
int instructionRegister;
int memory[];

public:
    Simpletron(){};
    void LoadMemory();
    void DisplayMemory();
    void Execute();

};

void Instructions(void);

int main(){
Simpletron mycomputer;

Instructions();

mycomputer.LoadMemory();    
mycomputer.Execute();

system ("pause");
return 0;

}

// Functions

void Instructions(){
cout << " Welcome to Simpletron! " << endl;
cout << " Please enter your program one instruction " << endl;
cout << " (or data word) at a time. I will type the " << endl;
cout << " location number and a question mark (?). " << endl;
cout << "*** You then type the word for that location. ...

0

Ohh, allright. Thanks, but the reason why I didn't use a class is because the professor wanted to use struct instead, and just in case, here's the Rect.h:

[CODE]#pragma once

include <iostream>

struct Rect {
float x;
float y;
float width;
float height;
};

typedef struct Rect RectStruct;

void assignRectValues(RectStruct , float, float, float, float);
void printRectValues(const RectStruct
);
float calcRectArea(const RectStruct *);
void calcMinMaxValue(float &, float &);

using namespace std;
[/CODE]

0

Hey, I keep getting this error, but from its description, I can't really tell how to fix it besides from what I've already tried, so any explanation would be great. The error I get is: clientrectlib.cpp(32) : error C2664: 'calcMinMaxValue' :cannot convert parameter 1 from 'overloaded-function' to 'float &'.

The code is the following: (This is clientrectlib.cpp)
[CODE]#include <iostream>

include "Rect.h"

using namespace std;

int main() {
cout << "Client to test the Rect library\n";

cout << "Creating some variable of type Rect ...." << endl;
RectStruct *rect01 = new RectStruct;
RectStruct *rect02 = new RectStruct;
RectStruct rect03;

cout << "Assigning values to them ...." << endl;
assignRectValues(rect01,10.51,20,40.77,50);
assignRectValues(rect02,20.83,30,80.99,10);
assignRectValues(&rect03,10.7,8.9,10,100);

cout << "Printing out their fields .. " << endl;
printRectValues(rect01);
printRectValues(rect02);
printRectValues(&rect03);

cout << "Printing out their areas .. " << endl;
cout << "Area of rect01: " << calcRectArea(rect01) << endl;
cout << "Area of rect02: " << calcRectArea(rect02) << endl;
cout << "Area of rect03: " << calcRectArea(&rect03) << endl;

cout << "Comparing the area of rect01 and rect03... " << endl;
cout << "The area of rect01 is " << calcRectArea(rect01) << endl;
cout << "and area of rect03 is " << calcRectArea(&rect03) << endl;
calcMinMaxValue(min, max);

return 0;

}[/CODE]

and (This is Rect.cpp)

[CODE]#include "Rect.h"

void assignRectValues(RectStruct *r, float xcoord, float ycoord, float widthValue, float heightValue) {
r->x = xcoord;
r->y = ycoord;
r->width = widthValue;
r->height = heightValue;
return;
}

void printRectValues(const RectStruct *r) {
cout << "(x,y) = (" << r->x << ", ...

0

Hey there, I'm having trouble getting my program to display the students and class summary using classes. What I'm unsure of is where the problem lies, whether it is a displacement of set/get functions or the content in my StoreStudent function is incorrect, or perhaps something else I might have missed. Anyways, any help, guidance, or helpful sites maybe, would be extremely helpful. This is my code so far:

[CODE]# include <iostream>

include <iomanip>

include <string>

include <fstream>

using namespace std;

ifndef STUDENT_H

define STUDENT_H

// Class

class Student{
private:
string name,
last;
int age;
char gender;
int size;
int *gptr;
public:
Student();
Student(int, int);
~Student();

     int CreateStudent();
     void StoreStudent(string, string, string, int, char, int[], int);
     void DisplayStudent();
     char StudentGrade(int);
     int StudentAvg(int []);

     void setName(string);
     string getName();
     void setLast(string);
     string getLast();
     void setAge(int);
     int getAge();
     void setGender(char);
     char getGender();

};

endif

[/CODE]

[CODE]// This programa creates a miniregister that allows the user
// to create classes, insert students into those classes,
// display the students records of the classes, as well as
// show the class summary.

include "Student.h"

include <iostream>

include <iomanip>

include <string>

include <fstream>

using namespace std;

//Prototypes

bool CheckClass(string ClassName);
int CreateClass();
void DisplayClass();
void Instructions(void);
int Menu(void);

Student::Student(){
gptr = new int[3];
size = 0;
}

Student::Student(int n, int m_size){
gptr = new int[n];
size = m_size;
}

Student::~Student(){
delete[] gptr;
}

void Student::setName(string N){
name = N;
}

string Student::getName(){
return name;
}

void Student::setLast(string l){
last ...

0

Now all it produces is a bunch of 0's. Right now, I'm just testing it with DisplayStudent and this is what I put so far:

[CODE]int Student::StoreStudent(string ClassName, string name, string last, int age, char gender,int grade[], int size){
// This function stores the student information into the file

ofstream Class;

ClassName.append(".dat");

Class.open(ClassName.c_str(),fstream::app | fstream::out);

Class << name << endl;
Class << last << endl;
Class << age << endl;
Class << gender << endl;
Class << size << endl;
Class << grade << endl;
for(int i = 0; i < size; i++){
        Class << grade[i] << endl;
}

Class.close(); 

}

int Student::DisplayStudent(){
int age;
string name;
string last;
char gender;
int size;
int *grade;
float average;
Student person;

ifstream Class;
string ClassName;

 cout << "Enter a class: " << endl;
cin >> ClassName;

cout << "\n";
if (CheckClass(ClassName)==true){
     ClassName.append(".dat"); // Adds ".dat" to the file
     Class.open(ClassName.c_str(),fstream::in);

     //Class >> size;

     grade = new int[size];

     Class >> name >> last >> age >> gender; 
     for (int i = 0; i < size; i++){
         Class >> grade[i];
     }

     while(!Class.eof()){
         average = person.StudentAvg(grade);

         cout << name << " " << last << setw(10) << age << setw(5) 
         << gender << setw(5); 
         for (int j = 0; j < size; j++){
             cout << grade[j] << setw(5);
         }
         cout.precision(2);
         cout << average;
         cout << "  " << person.StudentGrade(average) << endl;

         Class >> name >> last >> age >> gender;
         for (int k = 0; k < size; k++){
             Class >> grade[k];
         }
     }

     cout << ...
0

Hey, I haven't been able to figure out how to successfully display the students nor class.

These are my two functions:

[CODE]int Student::DisplayStudent(){
int age;
string name;
string last;
char gender;
int size;
int grade[size];
float average;
Student person;

ifstream Class;
string ClassName;

 cout << "Enter a class: " << endl;
cin >> ClassName;

cout << "\n";
if (CheckClass(ClassName)==true){
     ClassName.append(".dat"); // Adds ".dat" to the file
     Class.open(ClassName.c_str(),fstream::in);

     Class >> name >> last >> age >> gender; 
     for (int i = 0; i < size; i++){
         Class >> grade[i];
     }

     while(!Class.eof()){
         average = person.StudentAvg(grade);

         cout << name << " " << last << setw(10) << age << setw(5) 
         << gender << setw(5); 
         for (int j = 0; j < size; j++){
             cout << grade[j] << setw(5);
         }
         cout.precision(2);
         cout << average;
         cout << "  " << person.StudentGrade(average) << endl;

         Class >> name >> last >> age >> gender;
         for (int k = 0; k < size; k++){
             Class >> grade[k];
         }
     }

     cout << "\n" << endl;

     Class.close(); 
     return 0;
}
else {
     cout << "Class does not exist. " << endl;
     return 1;
 }

}

int DisplayClass (){
//This function displays the summary of the class

 string name;  // Variable of the first name
 string last; // Variable that contains the last name
 int age; // Variable of the age
 char gender;  // Variable of the gender
 int size; 
 int grade[size];
 int i, k;

 int gradetotal[size]; //={0,0,0,0,0};
 int AgeTotal;    

 float gradeavg[size]; // Variable used to store the average of each ...
0

Well , I've changed my whole program a bit since the last one shown. So maybe it was something I added that is messing it up. I know that I have to fix the DisplayStudent and DisplayClass a bit yet, but I don't know why my CreateStudent functions isn't working properly (for me at least). This is my latest update of my program:

[CODE]# include <iostream>

include <iomanip>

include <string>

include <fstream>

using namespace std;

ifndef STUDENT_H

define STUDENT_H

// Class

class Student{
private:
string name,
last;
int age;
char gender;
int m_size;
int *gptr;
public:
Student();
Student(int size);
~Student();

     int CreateStudent();
     int StoreStudent(string, string, string, int, char, int[]);
     int DisplayStudent();
     char StudentGrade(float);
     float StudentAvg(int []);

};

endif

[/CODE]

[CODE]// Carlo Rodriguez
// 22/3/10
// 801-08-5871
// carlo.rodriguez@uprrp.edu

// This programa creates a miniregister that allows the user
// to create classes, insert students into those classes,
// display the students records of the classes, as well as
// show the class summary.

include "Student.h"

include <iostream>

include <iomanip>

include <string>

include <fstream>

using namespace std;

//Prototypes

bool CheckClass(string ClassName);
int CreateClass();
int DisplayClass();
void Instructions(void);
int Menu(void);

Student::Student(){
m_size = 3;
gptr = new int[3];
}

Student::Student(int size){
//How many grades would you like to save?
m_size = size;
gptr = new int[size];
}

Student::~Student(){
delete[] gptr;
}

int main()
{
// Declaring variables
int option;
Student person;

// Este while es para que el programa siga corriendo mientras que sea escogido ...

0

Hmm, allright well I have it like this in CreateStudent function now:

[CODE]int Student::CreateStudent (){
// This function allows the user to insert as many students he/she wants
// to the class

// Variables required for the function
int age;
string name;
string last;
char gender;
int size;
int *grade;
int j, i;
int students;
Student person;
//char fullname[25];
int Age;
char Gender;
int Grade;

fstream Class;
string ClassName;

cout << "Enter a class: " << endl;
cin >> ClassName;

if (CheckClass(ClassName)==true){              
     cout << "How many students would you like to enter: " << endl;
     cin >> students;

     for (i = 0; i < students; i++){
         // Asks the user how many students he/she would like to enter
         // and for each one it asks the user to enter the student record
         cout << "Enter student information: " << endl;
         cout << "Enter first name: " << endl;
         cin >> name;
         cout << "Enter last name: " << endl;
         cin >> last;
         cout << "Enter age: " << endl;
         cin >> age;
         cout << "Enter gender: (M or F)" << endl;
         cin >> gender;
         cout << "How many grades would you like to enter? " << endl;
         cin >> size;
         Student Student(size);
         grade = new int[size];
         cout << "Now enter " << size << " grades:" << endl;
         for (j = 0; j < size; j++){
             cout << "Enter grade " << j + 1 << ": " << endl;
             cin >> grade[j];
         }    

     person.StoreStudent(ClassName, name, last, age, gender, grade); ...