C/C++ :: Program That Reads 3-by-4 Matrix And Displays Sum Of Columns

Nov 18, 2014

I'm not sure why Im getting a wrong Sum. of the Columns.

Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:

double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)

Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:

Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0

#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;

[Code].....

View 1 Replies


ADVERTISEMENT

C/C++ :: Program To Sum Rows And Columns Of A Matrix?

Apr 23, 2014

Im using apmatrix and im inputting values into a 4 by 4 matrix and im getting all these errors that have nothing to do with my cpp file so im guessing its apmatrixies fault. Also I put in the cpp and header file of both apmatrix and apvector into my project folder. Heres my code:

// Libraries
#include "apmatrix.h"
#include <iostream>
//cout, standard output
// <<, stream insertion operator

[code]....

My errors are:

error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.c:program filesmicrosoft visual studio 11.0vcincludexkeycheck.h2421TheMatrix

4IntelliSense: identifier "EMIT" is undefinedc:Program FilesMicrosoft Visual Studio 11.0VCincludeyvals.h4911TheMatrix

and a bunch are repeated

View 1 Replies View Related

C/C++ :: Array Implementation Of Stack To Reverse Columns In Matrix

Dec 1, 2014

I had the following question in my exam paper and only got 1.5 out of a possible 6 marks. This is the question:

Given the Matrix class:

class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);
[Code] ....

Use the linkedStackType class (Array implementation of stack) and write a function reverseCols to reverse the order of columns in the matrix. Note that reverseCols is not a member function of the Matrix class therefore only the public interface of matrix can be used.

//Implementation of Stacks as Array
template<class Type>
class stackType: public stackADT<Type> {
public:
const stackType<Type>& operator=(const stackType<Type>&);

[Code] ....

What is the correct solution must be to reverse the columns of the matrix?

View 1 Replies View Related

C/C++ :: Iterate 2D Matrix In Order To Exchange Columns And Rows Using Pointers

Jan 19, 2014

I am trying to iterate a matrix in order to exchange rows and columns element by element. Although the function that exchanges the rows has come out well, i don't seem to figure out how to do the same on columns.The columns switch for a matrix like

1 2 3
1 2 3
1 2 3

if i try to switch column 3 and 2,is:

1 3 2
1 3 2
1 2 3

Here are both of the functions:

void interchange_rows(int *p,int n,int r1,int r2){
    int temp;
    for(int i=0;i<n;i++){
            temp=*(p+r1*n+i);
            *(p+r1*n+i)=*(p+r2*n+i);
            *(p+r2*n+i)=temp;
   
[Code] ......

View 1 Replies View Related

C# :: Program That Displays Array Of Labels

Oct 7, 2012

I'm attempting to write a program that displays an array of labels; however, I can't seen to make the labels appear in the form. I've set some of the properties, but still not luck.

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code]...

View 4 Replies View Related

C :: Program That Accepts First / Last Name And Displays It Through Another Function

Sep 25, 2014

I was trying to code a program that accepts your first name and then last name and then displays it through another function. I have checked that the assignments are between similar type of variables and pointers, but I don't seem to get it right.

When first input is taken and then second one, the first one's value changes to same as the second. E.G if first name is L and second name is S and after second input both variables, first and sec, become equal to S. Why?

Code:

#include <stdio.h>
#include <stdlib.h>
//FUNCTION PROTOTYPES
char *input(void);
void show(char *f,char *s);

[code]....

View 7 Replies View Related

C++ :: Program Displays Not Found Even If Find ID Number

Oct 1, 2014

This is just the portion of my program. This program displays Not Found even if the id number is found.

void search(void) {
char ID[10];
int i, found;
cout<<"Enter ID to search: ";
gets(ID);
found=0;
for(i=0;i<top;i++)

[Code] .....

Here's the incorrect output

Enter ID to search: 111

Not found
Name: jude
ID: 111
Semester: 1
Major: IT

I just want to remove the "Not found".

View 1 Replies View Related

C :: Program That Displays Menu Of Commands For User To Choose From

Aug 1, 2013

I've read that we can write a program that displays a menu of commands for the user to choose from.We can write some functions that implement these commands, then store pointers to the functions in the array :

Code:
void ( *file_cmd[])(void) = { new_cmd , open_cmd }; // 2 cmd's for simplicity

We can get a similar effect with a switch statement but using an array of function pointers gives us more flexibility since the elements of the array can be changed as the programm is running.

I decided to write an example about this in order to understand better the context, I am facing some problems though :

Code:
#include<stdio.h>
#include<stdlib.h>
typedef void (*p_foo) (int);
void foo(int x);
void foo2(int y);

[Code] .....

The problems are :

Code:
TEST2.c:9: warning: initialization from incompatible pointer type
TEST2.c:9: warning: initialization from incompatible pointer type
TEST2.c:25: error: too few arguments to function "*(arr + (long unsigned int)((long unsigned int)i * 8ul))"

View 14 Replies View Related

C++ :: Create Program That Displays Median Of Array Using Pointers

Feb 27, 2013

The assignment is to create a program that displays the median of an array using pointers. Assume the array is already in ascending or descending order.I'm getting errors currently on the bottom two "return median;" statements.The code that I have so far is as follows...

#include <iostream>
using namespace std;
char again;
int getMedian(int*, int);
const int constant = 100;

[code]....

View 3 Replies View Related

C++ :: Writing Program That Computes Factorial Of Number And Displays It?

Oct 24, 2014

write a program that computes the factorial of a number and displays it. A factorial of a number (written N!) is defined as N * (N-1) * (N-2) * (N-3) ... *1 In other words, 5! = 5 * 4 * 3 * 2 * 1 = 120 and 3! = 3 * 2 * 1 + 6.

Example of output 15 is 1.30767e+012

Can't get it to display error when user enters a number lower than 2 or higher 60.

// Program to calculate factorial of a number
#include <iostream>
#include <iomanip>

[Code].....

View 13 Replies View Related

C :: Program That Displays Each Digit Of Integer In English - Zeros Won't Display

Apr 24, 2014

I'm new to C programming and in my first computer science class. Our assignment was to write a program that displays each digit of an integer in English. I wrote the following but cannot figure out why it won't display zeros. When I execute and type in the number 1,000, I get "zero."

Code:
#include <stdio.h>
int main (void)
{
int x, y = 0;
printf ("This program displays each digit of an integer in English.

[Code] ....

View 5 Replies View Related

C/C++ :: Program That Reads A File?

Jan 21, 2015

I wrote the following program:

#include "stdafx.h"
#include "string.h"
#include "ctype.h"

[Code].....

View 1 Replies View Related

C/C++ :: Program Takes Integer Input And Displays Each Digit On New Line From Right To Left

Jan 23, 2015

I'm trying to create a program that takes an integer input and displays each digit on a new line from right to left.

An example of this would be:

Enter an integer: 657
Digit (1): 7
Digit (2): 5
Digit (3): 6

So far I have this:

#include <stdio.h>
#include <math.h>
int main() {
int i, input, output;
printf("Enter an integer: ");
scanf("%d", &input);
if(input == 0)
printf("Digit (1): 0");

[Code] ....

It works perfectly fine, but I just learned that I am not allowed to use the #include <math.h> so I have to take out floor, log, and pow.

I'm pretty sure I have to do some sort of while or for loop to get the results, but how to do it.

View 6 Replies View Related

C++ :: Program That Reads In Ten Whole Numbers And Output Sum

Jan 23, 2014

Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.

Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.

this is what i got but it wont run saying there is an error

#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;

[Code] ....

View 5 Replies View Related

C/C++ :: A Program That Repeatedly Reads In Values?

Sep 26, 2014

I started to write a program that repeatedly reads in values for a,b and c and find the root of the polynomial

ax^2 + bx + c = 0

The program should print out for example:

two complex roots: root1 = -1.00000 + i*1.41421
root2 = -1.00000 - i*1.41421

My code:

#include <stdio.h>
#include <math.h>
int main(void){
int a,b,c;
printf("Choose the values of a, b and c for the equation ax^2 + bx + c");
scanf("%d%d%d
",a,b,c);

[code].....

View 6 Replies View Related

C :: Program That Reads Number Of Digits From File?

Jan 16, 2014

I've been working on a program that displays the number of digits in each line of a file, but I feel stuck. Take for example a file that contains these characters:

6347aaa9
54j
811111
6a
709

And I'm trying to display a result like this

1 //that's the number of the line 5 //the number of digits
2 2
3 6
4 1
5 3

Here's what I've written so far:

Code:
#include<stdio.h>
int main() {
char a=0;
int number_of_digits=0, linescount=0, num, number_of_digits_per_line=0;
FILE *inputFile;
if(!(inputFile=fopen("C:TestTest.txt","r")))

[Code]..

I also thought of using fgets and strlen but I am not very good with them and couldn't get the program to work correctly. It did work but it displayed all characters, letters included, not only digits.

View 2 Replies View Related

C++ :: Write A Program That Reads Data From A File?

Feb 26, 2013

Write a program that reads data from a file (use the attached data file). These data are a student name and 3 test scores. The program should calculate the average of the 3 test scores, and display the name, 3 test scores, and the average to the monitor.

Useful tips:
a) Include the following header files: iostream, fstream, iomanip, and string
b) The name of the data file is “datafile.txt”, you need to save the file in the same folder of the source file.
c) use the manipulators (setw, setprecision, setfill, showpoint, fixed) to format the average with 1 digits after decimal point as following.
d) Use character ‘ ’ for tab.

View 3 Replies View Related

C++ :: Program That Reads In A Sequence Of Binary Digits?

May 11, 2013

c++ program that reads in a sequence of binary digits (values 0 and 1) and stores them into a STL container. The input should terminate on any input that is not a 0 or 1. After finishing the read-process, apply a "bit-stuffing" algorithm to the container. In this case the bit stuffing should occur after four consecutive bits of the same value.i,e. four 0's or four 1's.. Also write the de-stuffing code to process the stuffed data to recreate the original data and verify that the original data is recovered correctly.

View 6 Replies View Related

C++ :: Write Program That Reads Group Of Chars?

Nov 28, 2014

Write a program that reads a group of chars till $. Then, compute # of vowels, # of digits, # of word and # of special chars. Your program should display all required results.

So in what way should I do it? Loop, array, ...?

View 13 Replies View Related

C :: Using Arrays - Program That Prompts For And Reads In Test Scores

Feb 11, 2013

Write a program that prompts for and reads in test scores. You may assume that valid test scores will be integer values between 0 and 100. You may also assume that the user will not enter more than 35 test scores. Use a preprocessor directive to define this value. User input will be complete when the user enters a -1 for the test score. When all of the test scores have been entered, the program will print out the scores. Use a while or do-while loop to read in the values. Use a for loop to print out the values.

Sample output:
Enter test score 1: 88
Enter test score 2: 67
Enter test score 3: 74
Enter test score 4: 94
Enter test score 5: 79
Enter test score 6: 56
Enter test score 7: -1
Number of scores entered: 6
Test scores entered : 88 67 74 94 79 56

View 14 Replies View Related

C :: Program That Reads In TXT File And Searches Through Text For Keyword?

Nov 8, 2014

I'm working on a program that reads in a .txt file and searches through the text for a keyword. If it gets a hit on the keyword, the line number where the keyword is located and the line that contains the keyword is printed out. What I have now doesn't catch every occurance of the keyword "a".

Code:

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {

[Code]......

View 4 Replies View Related

C++ ::  program That Reads Into String Object A Name With Three Blanks Between First And Last Names

Oct 4, 2014

" Write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. Write a function subprogram that displays its string argument two times. Call this function display the first name for times and then to display the last name six times."

I completed coding the first part of this task with the strings and combining strings together. However, i have having trouble with the other half of this task. It begins from "Write a function subprogram to display the last name six times." This is where i have so far --

#include <iostream>
#include <string>
using namespace std;
int main()
{
// Defining the strings

string firstname, lastname;
string wholename;
string greet = " Hi ";

[code]....

View 2 Replies View Related

C++ :: Write Program For Class That Reads From Input File?

Mar 7, 2013

I am trying to write a program for class that reads from an input file the month, year & total collected. I am using notepad for the input file.

This is what the notepad file looks like
-----------------------------------
March 2013 63924.62

Why does it give me random numbers in the output rather than what the notepad has?

Also, the outfile is completely blank.

#include <iostream>
#include <iomanip>
#include <fstream>

[Code].....

View 2 Replies View Related

C/C++ :: Program That Reads Data From A Text Document And Allows To Modify

Apr 30, 2015

I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.

#include <fstream>
using namespace std;
//named constants
const int MAX=100; //maximum flights
const int SIZE=20; //maximum characters
//struct definition
struct FlightType
{
char name[SIZE];

[Code]...

View 1 Replies View Related

C++ :: Program Which Reads TIFF Files And Shows Header

Dec 13, 2013

I have program which reads tiff files, and shows header.

Code:

#include <iostream>
#include <fstream>
using namespace std;
#define II 1
#define MM 2
typedef struct {
short unsigned byte_order;

[Code] ....

but I have a problem, my program doesn't shows:

ImageWidth
ImageLength
XResolution
YResolution

I must do this, without using another library like libtiff...

View 1 Replies View Related

C :: Program That Reads Alphanumeric Characters And Computes Average ASCII Value

Feb 16, 2015

Write a program that reads alphanumeric characters from the keyboard, and computes the average ascii value of the alpha numeric characters, the average alphabetical character, the average numeric character and the average uppercase character. Outputting each, you program should terminate reading once it read a non-alphanumeric character.

Here's what i have so far.

Code:
#include <stdio.h>
#include <ctype.h>
int main(void) {
int value = 'a';
int digit_loop = 0;
int alpha_loop = 0;
int upper_loop = 0;

[Code] ....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved