C :: Input Matrices Dimensions - Calculate Elements Of Products
Nov 14, 2013
This is my code and it's not giving me the right output
Code:
#include <stdio.h>
int main() {
int dim;
int i, row, col;
// inputting matrices dimensions
int M0, M1, M2;
[Code] ....
The output should give me this:
Input 2
Correct Output 2 5 4 10
View 10 Replies
ADVERTISEMENT
Jul 3, 2013
Code:
#ifndef CIRCLE_H
#define CIRCLE_H
class Circle {
public:
//constructors
Circle();
Circle(double r);
[code]....
The function isBigger() returns true (or false) if the radius of the Circle instance on which the function is invoked is bigger (or smaller) than the radius of the Circle instance passed to the function.: How to implement this function?
View 5 Replies
View Related
Oct 2, 2013
What I'm trying to accomplish is to ask the user what their floor plan is (in square feet), have them pick what kind of material they want and give them a general price.
Which is working out great so far, but I would also like to add a loop at the end that cycles back if they want to re-do the estimate with a different material selection and if not exit out the program.
I've been trying do while and if/else loops but i can't get them to work right.
#include <iostream>
#include <string>
using namespace std;
int main() {
string custName, selection;
int custNumber, floorSize, material, contactSystem;
[Code] ....
That's basically what I've come up with so far minus all the erroneous attempts. Though as is I technically complete the assignment, I would like the extra credit from making the last part loop.
View 1 Replies
View Related
Oct 29, 2014
New to C Programming, I have a problem with a little program I made that calculates the product of two matrices.
And here is the error I get:
View 4 Replies
View Related
Jan 8, 2015
I am unable to input the correct form for matrices multiplication. I have an exam tomorrow in which I need to use this.
Code:
#include <stdio.h>
#include <conio.h>
int main() {
float a[10][10], b[10][10], c[10][10];
int i, j, k, l, n=0, m=0, x=0, y=0, sum=0;
printf("Enter the number of rows and collumns of the first matrix");
scanf("%d %d", &n, &m);
[Code]...
View 7 Replies
View Related
Oct 23, 2013
Use function decomposition.
-To prompt user to enter value and assign it to correct position in array
-calculate the average of an array
-display all element.
-display average.
For some reason, i keep getting error and it doesn't compile. I use Dev-C++
Here is my code:
#include <iostream>
#include <iosmanip>
#include <math.h>
using namespace std;
const int SIZE = 5;
const int LINE = 4;
//function prototypes
void getData(int arr[]);
[Code]...
My error is on line 69. I don't see anything wrong with it.
If i take out setw(3), it doesnt get any error but for some reason it doesnt run. Possible i did something wrong there?
View 2 Replies
View Related
Nov 28, 2013
Write a C/C++ program that reads a boolean expression in sum-of-products form and generates the sum-of-minterms form (canonical form). Use single letter to represent variables. The following symbols will be used to represent operators: NOT: ~, AND: *, OR: +. Other operators won't be used.
Examples of execution:
number of variables: 2
SOP expression: ~A+B
output: ~A*~B + ~A*B + A*B
number of variables: 3
SOP expression: x*y*z + ~x*~y + y*~z
output: x*y*z + ~x*~y*z + ~x*~y*~z + x*y*~z + ~x*y*~z
View 3 Replies
View Related
Apr 29, 2013
I am using Dev C++ compiler on Windows 7 and was programming a piece of code that is supposed to do the following -
Create a structure to store information about products for sale in a store. It should store information about the product name, the price, and the product number and then create an array of products called Inventory. Add five products to your inventory.
But for some reason, which is unknown to me, I always seem to get a compiler error. And this is what i have so far -
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct product{
char name[30];
int product_number;
double price;
[Code] ....
View 4 Replies
View Related
Jan 15, 2015
Given a product category and subcategory representation:
a. Come up with a tree data structure to minimally (in terms of storage) represent this
b. Write a program to convert the given representation (shown in example below) to this
c. Write a function to output the tree structure in a nice human readable format
Note:
a. There can be any number of levels of depth
b. Rows may be repeated in input, but need to feature only once in the final tree.
Example category list (read this input from a file):
everything else|office supplies
electronics|video games
electronics|video games|accessories
electronics|video games|accessories|headsets
electronics|video games|accessories|flight controls
electronics|video games|accessories|joysticks
View 5 Replies
View Related
Mar 27, 2013
Summary: 6 companies have a product in 5 different warehouses. Each company is identified by a positive ID number and each warehouse is identified by a number (1 for the first, 2 for the second,…)
Object: the object of this assignment is to write a C++ program which asks the user to enter a company ID number, and the number of products in each of the warehouses. It then computes and prints the total number of products for that company
If the total number of product is less than 100, it prints the message “place a new order”
Input: for each company, its ID, and the number of products in each warehouse with appropriate prompt messages.
Example: Enter company ID number: 101
Enter number of products in warehouse #1:30
Enter number of products in warehouse #2:60
Enter number of products in warehouse #3:0
Enter number of products in warehouse #4:5
Enter number of products in warehouse #5:27
The total for company 101 is:122
Output: for each company, the total number of product, and the message “place a new order” if the total number of product is less than 100.
Method:
1. Define global variable, int total_prod to hold the total number of products for a company
2. define the function void compute_total() that uses a loop to read the number of the products in all warehouses for one company, computer the total number of products and store it into the global variable total_prod.
3. Define the function void new_order() that determines if a new order need to be placed as follows: if the total number of products (in the global variable total_prod) is less than 100, it prints the message “place a new order”
4. Your function main does the following in a loop:
- read a company ID number
- call function compute_total() to read the number of the product in all warehouses for that company, and to compute their sum
- print the total number of the product for that company with an appropriate message
- call the function new_order() to determine if a new order need to be placed.
View 17 Replies
View Related
Mar 19, 2014
I am compiling using Microsoft Visual C++ and I am trying to create a program that ask's the user for 10 numbers, and these numbers will have to be loaded into a one dimensional array of 10 elements. I read up online as well as my book and looked at sample programs, then created mine which was similar to the sample programs I looked at, but the sample ones compile , while I get C2059 and C2061 Syntax Errors. I am new to programming so I understand it could be one small thing but I after looking over it I am completely clueless.
Heres my program:
Code:
#include
<iostream>
int
main()
[Code] .....
My program is also attached
View 5 Replies
View Related
Nov 4, 2013
I want to input the elements of a two dimensional array in the same line . So while giving input . when i press enter . it should remain on the same line ? HOW to do that ?
View 1 Replies
View Related
Dec 16, 2013
Write a function that takes a picture and two integer values and stretching the image by dimensions.
View 8 Replies
View Related
Oct 29, 2013
If I have a one-dimensional array of length 10, vector<int> x, and I want to assign all the elements to value 5, then I can do the following:
Code:
vector<int> x(10);
x.assign(10, 5);
(I can also do this in x's constructor, but in my scenario I want to repeatedly assign x's elements in a loop, without having to construct a new vector in memory each time.)
If I now have a two-dimensional vector, vector<vector<int> > y, and I want to assign the first vector to length 20, the second vector to length 10, and each element in the second vector to value 5, then I can do the following:
Code:
vector<vector<int> > y(20, vector<int> (10));
for (int i = 0; i < 20; i++) {
y[i].assign(10, 5);
}
But is it possible to do this without the loop? Can I make the two-dimensional assignment in just one line, in the same way that the one-dimensional assignment was made?
Perhaps it would like something like the following, which is not correct but illustrates what I mean:
Code:
y.assign(20, assign(10, 5));
Another way of doing this would be the following:
Code:
y.assign(20, vector<int> (10, 5));
But wouldn't this cause the memory in the second array to be dynamically allocated each time? I don't want to do this - I want to keep the same memory, but just assign the elements to 5.
View 1 Replies
View Related
Feb 27, 2015
I added my assignment to attachment, i need to calculate the sum for input values of x and n this is my code:
#include<stdio.h>
#include<math.h>
main() {
float gore,dole,s,x;
int n,i,j,z;
s=0;
i=0;
j=0;
[Code] ....
gore calculates x^(2*i)-3 and dole is for (2+i)! for input x=1 and n=1 i get -2.0 output which is the value of x^(2*i)-3 the (2+i)! part gets ignored for some reason, for any other input i tried the output is 0 ....
View 6 Replies
View Related
Feb 9, 2014
I can't compile this code as I am at work and the computers are security protected, So i''l have to wait until i get home to test this, but I am pretty sure I am wrong. The problem is I have to create two vectors with 10 elements and input random numbers into it, then pick one of the elements of the second vector at random and append it to an element from the first vector at random. This has to be done 10 times and the I am assuming i have to print the 10 results. This is what I have:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
vector<int> random (10);
[Code] ....
View 11 Replies
View Related
Jan 6, 2015
I am writing a piece of code that simulates a random walk in 2 dimensions (an object chooses whether to move up, down, left or right randomly). I would like the program to run the simulation for many objects at the same time. The way i have written it means that for every object i add the code becomes about 40 lines longer. Any method that would simplify the code so that i could have many objects but not pages and pages of code.
#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
using namespace std;
double dist(int a, int b);
[Code] .....
View 5 Replies
View Related
Feb 18, 2013
I have a JPEG in memory as a char* and a bytesize, if I save it to disk with a .jpg extension it's a perfect JPEG file. The thing is, I don't want to save it unless it's a minimum width/height. I got it into memory using a socket recv() call. What should I do ?
View 6 Replies
View Related
Mar 13, 2013
I am trying to make a program that will calculate gpa using a transcript from an input file. The transcript includes the title of the subject, the letter grade, and the credits per class. However, I wouldn't know how many courses are in the file. How would I start to write out this program? The only things I can use are ifstream, ofstream, for-loops, if statements, and if-else statements.
View 3 Replies
View Related
Feb 19, 2014
Write code to do the following:
1) declare a variable ptr as a pointer to int and initialize it to NULL
2) dynamically allocate memory for an array of 100 elements
3) read 100 elements from the standard input device and store them in the array.
This is what I have so far, I'd like to know if its ok or if something is wrong.
int *ptr = NULL;
ptr = new int[100];
cin >> dataPtr [arr];
View 2 Replies
View Related
Apr 28, 2014
I need starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score. Here's what I have so far:
//This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;
int main(){
int score, slope;
double rating, handicap;
[Code] ....
View 4 Replies
View Related
May 24, 2014
I am trying to create a program that will calculate pi based on a user input for accuracy. If the user input .3 then when the leibniz infinite sum value at a particular i becomes less then the input of .3 then the loop will exit.
I have looked at a number of examples on the internet but I feel lost. I have put together working code that will infinitely output sums but I need the loop to stop when the sum value is less then the accuracy value.
My question is what is wrong with my while loop, why will it only give me infinite summations? How do I make it so that the loop will exit when my accuracy input is greater then the sum?
int main () {
double accuracy;
cout<<"Give an accurate number." << flush;//looks nice
cin>>accuracy;
int d;//initialize denominator
double pi = 0.0;
while(accuracy < d){
[Code]...
View 8 Replies
View Related
May 15, 2013
I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.
#include <iostream>
#include <cmath>
using namespace std;
double original_cost;
double discount;
double tax;
double total;
char answer;
[Code]...
View 2 Replies
View Related
Sep 12, 2013
I have created a program to calculate different measurements for a cylinder. Anyways, the end user has to input 3 variables.
Enter the lower radius: 6
Enter the upper radius: 5
Enter slant height: 2.236
The numbers are what "End User" would input. But I need to make it look like this when said "End User inputs the numbers.
Enter the lower radius: 6
Enter the upper radius: 5
Enter slant height: 2.236
Here is what I have for it, but I don't know what to put where.
printf("
Enter the lower radius: ");
scanf("%f", &lower_rad);
printf("Enter the upper radius: ");
scanf("%f", &upper_rad);
printf("Enter slant height: ");
scanf("%f", &slant_h);
View 1 Replies
View Related
Jul 15, 2014
I'm still fairly new to c++ and am having trouble with dynamic arrays. My task is to create an array for test scores. The user needs to define the size of the array and then input data to later sort and calculate the average.
Below is what I have so far. I am struggling with the user input part. I receive the following errors for the data input of the individual scores:
"error C2108:subscript is not of integral type"
"IntelliSense:expression must have integral or unscoped enum type"
Code :
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
//user input total number of scores
cout<<"Please enter the total number of test scores."<<endl<<endl;
[Code] ....
View 1 Replies
View Related
Jan 24, 2014
I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average
*/
#include <stdio.h>
int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;
int nTotal = 0; /* Declare and initialise the value */
float fAverage;
[Code]...
View 1 Replies
View Related